wpfxamlinner-classesnested-class

Creating an instance of a nested class in XAML


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
    {
    }
}

Something like :

<local: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.

I'm currently using Silverlight 4 with VS2010.

Thanks in advance for your help.


Solution

  • I was searching and searching, because if this is possible, I would like to know. Unfortunately, I found this on msdn:

    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.

    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)