Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 519
mahboub_mo Avatar asked Sep 03 '25 04:09

mahboub_mo


1 Answers

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>
{
}
like image 97
ColinE Avatar answered Sep 04 '25 17:09

ColinE