Accessing a nested type from xaml

 
 
  • Gérald Barré

Sometimes you need to access a nested type from XAML, for example when declaring a DataTemplate. The usual C# syntax MyClass.MyNestedClass does not work. Instead, you must use the .NET notation with a +:

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

As a sign of how uncommon this is, Visual Studio's syntax highlighting does not handle this syntax well.

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

Follow me:
Enjoy this blog?