Friday 29 December 2006

WPF/XAML - x:Type and nested classes

Well now I am getting started with XAML and WPF I am hoping to start blogging a bit more! So I was trying to reference a nested type with the {x:Type} markup extension and it wasn't working. Say you have a class as follows:

public class MyClass
{
    public class MyInnerClass
    {
    }
}

You want to reference the inner class (e.g. for a DataTemplate). The following XAML does not work

<DataTemplate DataType="{x:Type MyClass.MyInnerClass}">

What you need to do is:

<DataTemplate DataType="{x:Type MyClass+MyInnerClass}">

Thanks to Seb for the hint on that one!