Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 303
Pragmateek Avatar asked Nov 24 '10 17:11

Pragmateek


People also ask

Can we create instance of nested class?

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.

Can you nest classes in C#?

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.

What are the four types of nested classes?

As a member of the OuterClass , a nested class can be declared private , public , protected , or package private.

What is nested class with example?

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.


1 Answers

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 
like image 119
Ludovic Chabant Avatar answered Sep 21 '22 15:09

Ludovic Chabant