How to reference a generic type in the DataType attribute of a DataTemplate?

Gypsy picture Gypsy · Apr 4, 2012 · Viewed 13.8k times · Source

I have a ViewModel defined like this:

public class LocationTreeViewModel<TTree> : 
    ObservableCollection<TTree>, INotifyPropertyChanged
        TTree : TreeBase<TTree>

I want to reference it in the DataType attribute of a DataTemplate in XAML. How can I do that?

Answer

ColinE picture ColinE · Apr 4, 2012

No, you cannot express a generics type in XAML. You will have to create a concrete type that extends your generic one ...

public class FooLocationTreeViewModel : LocationTreeViewModel<Foo>
{
}