Accessing a nested type from xaml

 
 
  • Gérald Barré

Sometimes you need to access a nested type from XAML, for instance to declare a DataTemplate. You think that it is enough to use the usual syntax in C# MyClass.MyNestedClass, but this doesn't work! In fact, you must use the .Net notation using a +:

C#
public class MyClass
{
    public class MyInnerClass
    {
    }
}
XAML
<DataTemplate DataType="{x:Type myns:MyClass+MyInnerClass}" />

As a sign this is not common, the syntax highlighting of Visual Studio is weird with this syntax.

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?Buy Me A Coffee💖 Sponsor on GitHub