问题描述
我的MVP-PRISM WPF应用程序具有BaseView.现在由于某种原因,我们考虑将_presenter作为BaseView中的Templated字段.
I have a BaseView for my MVP - PRISM WPF application. Now for some reason we thought to make the _presenter as a Templated field in the BaseView.
之前,我将xaml表示为
earlier i had the view xaml representation as
<base:BaseView xamlns:base="clr address of the dll which had BaseView" >
</base:BaseView>
现在,因为我已经将BaseView
更改为BaseView<TPresenter>,
,那么我该如何编写Xaml?
now since i have changed the BaseView
to BaseView<TPresenter>,
So how shall i write the Xaml then?
推荐答案
从.NET 4 Framework
和XAML 2009开始,您就可以这样做.请参阅MSDN XAML中的泛型
You can do it since .NET 4 Framework
and XAML 2009.See Generics in XAML on MSDN
例如:
<my:BusinessObject x:TypeArguments="x:String,x:Int32"/>
对于.NET 3.5:
For .NET 3.5:
支持通用用法的可能解决方法包括定义一个 自定义标记扩展,可以返回通用类型,或提供 包装类定义,该类定义派生自泛型类型,但 使通用约束在其自己的类定义中变平整.
Possible workarounds to support generic usages include defining a custom markup extension that can return generic types, or providing a wrapping class definition that derives from a generic type but flattens the generic constraint in its own class definition.
这篇关于如何在XAML中指定泛型类型参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!