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.
To instantiate an inner class, you must first instantiate the outer class. Then, create the inner object within the outer object with this syntax: OuterClass.
In C#, a user is allowed to define a class within another class. Such types of classes are known as nested class. This feature enables the user to logically group classes that are only used in one place, thus this increases the use of encapsulation, and create more readable and maintainable code.
As a member of the OuterClass , a nested class can be declared private , public , protected , or package private.
A nested class is a class that is declared in another class. The nested class is also a member variable of the enclosing class and has the same access rights as the other members. However, the member functions of the enclosing class have no special access to the members of a nested class.
This question is pretty old, and I don't know if it would have worked with the version of WPF back in 2010, but now you can make it work by using the "real" (internal) name of the nested type:
<local:A+B />
If you've ever looked a disassembled code, that's how nested types look like:
ParentTypeName+Nested
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With