在 XAML 中创建嵌套类的实例 [英] Creating an instance of a nested class in XAML

查看:23
本文介绍了在 XAML 中创建嵌套类的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

XAML 文件(WPF UserControl)中,有没有办法引用在另一个类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 ... />

此语法不起作用,因为B"被解释为类A"中名为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.

我目前使用 Silverlight 4VS2010.

预先感谢您的帮助.

推荐答案

我一直在搜索和搜索,因为如果可以的话,我很想知道.不幸的是,我在 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屋!

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