如何在 DataTemplate 的 DataType 属性中引用泛型类型? [英] How to reference a generic type in the DataType attribute of a DataTemplate?
本文介绍了如何在 DataTemplate 的 DataType 属性中引用泛型类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样定义的 ViewModel:
I have a ViewModel defined like this:
public class LocationTreeViewModel<TTree> :
ObservableCollection<TTree>, INotifyPropertyChanged
TTree : TreeBase<TTree>
我想在 XAML 中 DataTemplate
的 DataType
属性中引用它.我该怎么做?
I want to reference it in the DataType
attribute of a DataTemplate
in XAML. How can I do that?
推荐答案
不,您不能在 XAML 中表达泛型类型.您将不得不创建一个扩展通用类型的具体类型......
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>
{
}
这篇关于如何在 DataTemplate 的 DataType 属性中引用泛型类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文