如何以其ClassName作为参数打开Silverlight ChildWindow? [英] How to open a Silverlight ChildWindow with it's ClassName as a parameter?
问题描述
嗨
我需要基于定义子窗口名称或类的参数创建一种方法来打开子窗口.
此参数存储在SQL的表中,我不知道该打开哪个女巫窗口,因为它取决于用户选择.
我以为我会使用通用类ChildWindow并创建类似以下内容的内容:
Hi
I need to create way to open a child window based on a parameter that would define the child window name or class.
This parameter is stored in a table in SQL and I don''t know in advance witch child window is supposed to be open for it would depend on a user choice.
I thought I''d use generic class ChildWindow and create something like:
ChildWindow cw = new ChildWindow();
//How to direct cw to myCwClass?
cw.Show();
我有很多子窗口,使用switch()命令或嵌套if只是不切实际.
Google并没有很大的帮助!
有谁知道实现此目标的方法或任何可以在其中看到示例的Web链接?
感谢
I have a lot of child windows and it''s just not practical to use the switch() command or nested if''s.
Google hasn''t been of great help!
Does anyone know a way to achieve this or knows any web link where I can see an example?
Thanks
推荐答案
您是否要打开数据库中命名的特定类?如果是这样,为什么不只使用Activator.CreateInstance
实例化该类并显示它呢?详细信息此处 [Type.GetType
将字符串类型转换为Type
对象. [ ^ ]
Are you trying to open the specific class named in your database? If so, why don''t you just useActivator.CreateInstance
to instantiate the class and show it? Details here[^]. You can get transform the string type into aType
object usingType.GetType
[^]
就是这样.谢谢皮特.
这是我的操作方法:
That''s it. Thanks Pete.
Here''s how I did it:
Type cwType = Type.GetType("myNamespace.myCwClass");
object cw = Activator.CreateInstance(cwType);
((ChildWindow)cw).Show();
我的5!
My 5!
这篇关于如何以其ClassName作为参数打开Silverlight ChildWindow?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!