将ObjectHandle转换为UserControl

时间:2011-12-08 15:33:33

标签: c# wpf silverlight reflection activator

如何将Remoting.ObjectHandle转换为UserControl类型?

我想动态实现UserControl:

UserControl myUserControl = (UserControl)Activator.CreateInstance(Assembly.GetExecutingAssembly().FullName, "Client.IndexView");

错误无法将“System.Runtime.Remoting.ObjectHandle”类型的表达式转换为“UserControl”

1 个答案:

答案 0 :(得分:6)

如果您使用Unwrap方法怎么办:

var instance = Activator.CreateInstance(Assembly.GetExecutingAssembly().FullName, "Client.IndexView");
UserControl myUserControl = (UserControl)instance.Unwrap();