I have a ViewModel defined like this:
public class LocationTreeViewModel<TTree> :
ObservableCollection<TTree>, INotifyPropertyChanged
where TTree : TreeBase<TTree>
I want to reference it in the DataType attribute of a DataTemplate in XAML. How can I do that?
In XAML 2006 this is not supported. You can, however, roll your own if you want to have this functionality.
This link has a nice tutorial on creating markup extensions.
Usage would be like this:
You have to choose and implement the syntax though. I suggest the VB notation since it won't interfere like the C# notation does with < and >.
Slightly improved version of MarkupExtension, work for classes upto 3 generic parameters.
The only way i could do this is to use
MarkupExtensions
.And to use it i just need to do this:
No, you cannot express a generics type in XAML. You will have to create a concrete type that extends your generic one ...
The {x:Type} markup extension supports allows generic type arguments to be specified as a comma separated list in parentheses.
Here's an example:
I am using .Net 4.5 on VS 2015, so your mileage may vary.