I have a class of MyClass<MyObject>
and want to set it as the DataType for a HierarchicalDataTemplate.
What is the syntax for this in XAML? (I know how to set namespaces, I need just the syntax for
<HierarchicalDataTemplate DataType="{X:Type .....
itowlson's approach is a good one but it is just a start. Here's something that will work for your case (and most, if not all, cases):
Then, you are able to create any type with any level of depth in your XAML. For example:
There's a few key ideas here:
In .NET 4.0, use below code.
http://illef.tistory.com/115
This is not supported in WPF 3.x out of the box (I think it may be in 4.0, but I'm not sure); but it's easy to set up with a markup extension.
First, you need to create a markup extension class that takes the type parameter as a constructor argument:
Now you use this markup extension in place of the x:Type extension:
Needless to say, this can be generalised to allow instantiation of arbitrary generic types; I haven't shown this because it adds a wee bit more complexity.