错误无法序列化嵌套的公共类型。为什么?

时间:2010-09-21 09:02:27

标签: wpf richtextbox

在执行此代码时出错 无法序列化嵌套的公共类型'System.Windows.Forms.AxHost + State'。

FlashControl我的usercontrol

<UserControl x:Class="Adminka.UserControls.FlashControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             xmlns:controls="clr-namespace:MyBlogUserControls;assembly=MyBlogUserControls">
    <Grid>
        <controls:FlashPlayer/>
    </Grid>
</UserControl>

FlashPlayer - 用于查看flash的usercontrol

fd是一个richtextbox,我需要替换TextBox上的FlashControl,但是会发生错误

error -  Cannot serialize a nested public type 'System.Windows.Forms.AxHost+State'.


    for (int i = 0; i < fd.Blocks.Count; i++)
    {
        var block = (fd.Blocks as BlockCollection).ElementAt(i);
        if (block is Paragraph)
        {
            var p = new Paragraph();
            for (int y = 0; y < ((Paragraph)block).Inlines.Count; y++)
            {
                var inline = ((Paragraph)block).Inlines.ElementAt(y);
                if (inline is InlineUIContainer)
                {
                    var elem = ((InlineUIContainer)inline).Child;
                    if (elem is FlashControl)
                    {
                        elem = new TextBox() { Text = string.Format(format, "FlashControl", (elem as FlashControl).FlashPlayer.Source) };
                    }
                    ((InlineUIContainer)inline).Child = null; \\error occurs here
                }
            }
            block = p;
        }
    }

如何在TextBox上替换FlashControl?

1 个答案:

答案 0 :(得分:0)

为了解决这个问题,我最终将我的类型声明移到我的课堂之外(因此它不再是'嵌套')。