在XAML中创建嵌套类的实例 [英] Creating an instance of a nested class in XAML
问题描述
在 XAML 文件(WPF用户控件)中,是否可以引用在另一类"A"中定义的内部类"B"?
in a XAML file (a WPF UserControl), is there a way to reference an inner class "B" defined in another class "A" ?
public class A
{
public class B
{
}
}
类似的东西:
<local:A.B ... />
此语法不起作用,因为在类"A"中将"B"解释为名为"B"的属性.
This syntax does not work because "B" is interpreted as a property named "B" in class "A".
我尝试了更多的外来语法,例如"::"或"+",但似乎都不起作用.
I've tried more exotic syntaxes like "::" or "+" but none seems to work.
我当前在 VS2010 中使用 Silverlight 4 .
预先感谢您的帮助.
推荐答案
我一直在搜索,因为如果可能的话,我想知道.不幸的是,我在 msdn 上找到了:
I was searching and searching, because if this is possible, I would like to know. Unfortunately, I found this on msdn:
您的自定义类不得嵌套 班级.嵌套类和点" 在其一般CLR使用语法中会干扰其他WPF和/或XAML 功能,例如附加属性.
Your custom class must not be a nested class. Nested classes and the "dot" in their general CLR usage syntax interfere with other WPF and/or XAML features such as attached properties.
因此,看来您无法使用点运算符引用嵌套类.至于通过XAML到达该内部类的替代方法,我的搜索还没有运气. :o(但这是一个相当有趣的问题,所以我将继续搜索.也许我会发现一些运气!:o)
So, it appears you can't reference a nested class with the dot operator. As for alternative ways of getting to that inner class through XAML, I haven't had any luck in my searches yet. :o( But this is a rather interesting issue, so I will continue searching. Maybe I'll find some luck! :o)
这篇关于在XAML中创建嵌套类的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!