WPF userconrol对象创建到AppDomain中 [英] WPF userconrol object creation into AppDomain

查看:104
本文介绍了WPF userconrol对象创建到AppDomain中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在编写wpfusercontainer应用程序,它将嵌入wpfuserconrols对象.要求是每个wpf userconrol都应创建到单独的appdomain中.我已经创建了示例wpf userControl类,并将该属性标记为可序列化". 这是代码

I am writing wpfusercontainer application,which will embed wpfuserconrols object. The requirement is each wpf userconrol should be created into the separate appdomain. I have create sample wpf userControl class and marked the attribute as "Serializable". Here is the code

//示例WPF用户控件

//Sample WPF usercontrol

 

[可序列化]

    [DataContract]

    [DataContract]

   公共局部类Sample_1:UserControl

    public partial class Sample_1 : UserControl

    {

    {

       公开Sample_1()

        public Sample_1()

        {

        {

            InitializeComponent();

            InitializeComponent();

        }

        }

    }

    }

 

 

 

//wpf userContainer应用程序

//wpf userContainer Application

 

 

公共MainWindow()

public MainWindow()

        {

        {

            InitializeComponent();

            InitializeComponent();

 

            //AppDomain初始化

            //AppDomain Initialization

            Ap1 = AppDomain.CreateDomain("Ap1");

            Ap1 = AppDomain.CreateDomain("Ap1");

            Ap2 = AppDomain.CreateDomain("Ap2");

            Ap2 = AppDomain.CreateDomain("Ap2");

 

           尝试

            try

            {

            {

 

                Sample_1 sp2 =(Sample_1)Ap1.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName,"WpfApplication1.Sample_1");

                Sample_1 sp2 = (Sample_1)Ap1.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, "WpfApplication1.Sample_1");

            }

            }

           捕获(异常e)

            catch (Exception e)

            {

            {

 

               字符串errMessage = e.Message;

                string errMessage = e.Message;

            }

            }

        }

        }

 

 

当我通过使用"Ap1.CreateInstanceAndUnwrap"创建Sample_1对象的实例时,方法,我在程序集"WpfApplication1,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null"中出现错误< 类型'WpfApplication1.Sample_1' 标记为可序列化.".我已经将Sample_1标记为可序列化,但是仍然出现此错误.谁能帮我.

When I am creating the instance of Sample_1 object by using "Ap1.CreateInstanceAndUnwrap" method, I am getting error " Type 'WpfApplication1.Sample_1' in assembly 'WpfApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.". I have already marked Sample_1 as serializable but still I am getting this error. Can anyone please help me.

 

致谢

Ravi

推荐答案

无法进行尝试.   UserControl必须位于主应用程序域中,因为主应用程序需要引用它.即使您将类标记为可序列化,也只有在基类(UserControl)下才能使用 也可以序列化,在这里不是这种情况.

What you are attempting is not possible.  The UserControl will have to be in the main app domain, since the main application needs to reference it.  Even if you mark your class as serializable, it will only work if the base class (UserControl) is also serializable, which is not the case here.

 

无法将UI元素加载到单独的应用程序域中.

There is no way to load a UI element into a separate app domain.


这篇关于WPF userconrol对象创建到AppDomain中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆