【问题标题】:Creating a custom usercontrol in silverlight with a string containing class name在 silverlight 中使用包含类名的字符串创建自定义用户控件
【发布时间】:2011-03-22 15:21:12
【问题描述】:

好吧,现在我有一个字符串,其中包含自定义控件类的名称,例如“MyBaseControl”

它的代码文件在代码中是什么样子的

公共类 MyBaseControl:用户控件

我需要使用我收到的字符串创建此控件的一个实例并将其添加到我的页面,我相信它与

var fieldControl = (UIElement)typeof(MyBaseControl).Assembly.CreateInstance("MyBaseControl");

但是在这种情况下,字段控制返回 null,有什么想法吗? :)

PS 为了进一步扩展它,我最终想创建这个基类的子类的实例,所以 var fieldControl = (UIElement)typeof(MyBaseControl).Assembly.CreateInstance("MySubControl");

【问题讨论】:

    标签: c# silverlight silverlight-4.0


    【解决方案1】:

    我已经对它进行了排序,没关系抱歉,我发现传入的字符串在类名之前也需要完整的命名空间:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-08
      • 2011-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多