我正在尝试在XAML代码中的Windows.Resources部分中使用通用类型。要附加对象集合的通知,我的泛型集合继承自ObservableCollection,如下所示:
public class PresentationModalCollection<T> : ObservableCollection<T>
{
public PresentationModalCollection(List<T> list) : base(list)
{
}
}
有一个扩展方法返回List的ObservableCollection,如下所示:
public static class ExtensionMethods
{
public static PresentationModalCollection<T> ToObservableCollection<T>(this List<T> list)
{
return new PresentationModalCollection<T>(list);
}
}
现在,我想在我的Window.Resources中使用PresentationModalCollection,如下所示:
<Window.Resources>
<LearningWPF:PresentationModalCollection x:Key="customers">
<LearningWPF:Customer FirstName="Mohammad" LastName="Azam" />
</LearningWPF:PresentationModalCollection>
</Window.Resources>
当然,上面的代码不起作用。是否有任何方法可以执行上述操作而无需创建继承自ObservableCollection的类CustomerCollection?
答案 0 :(得分:2)