Accessing a nested type from xaml

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 +:

public class MyClass
{
    public class MyInnerClass
    {
    }
}
<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.

Leave a reply