如何在 XAML 中指定泛型类型参数
我有一个用于我的 MVP - PRISM WPF 应用程序的 BaseView。现在出于某种原因,我们考虑将 _presenter 作为 BaseView 中的模板化字段。
早些时候我有像现在一样的视图 xaml 表示
<base:BaseView xamlns:base="clr address of the dll which had BaseView" >
</base:BaseView>
,因为我已将 BaseView
更改为 BaseView
那么我该如何编写 Xaml 呢?
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.
earlier i had the view xaml representation as
<base:BaseView xamlns:base="clr address of the dll which had BaseView" >
</base:BaseView>
now since i have changed the BaseView
to BaseView<TPresenter>,
So how shall i write the Xaml then?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 .NET 4 Framework 和 XAML 2009 开始,您就可以做到这一点。
参阅 MSDN 上的 XAML 中的泛型
请 实例:
对于.NET 3.5:
You can do it since
.NET 4 Framework
and XAML 2009.See Generics in XAML on MSDN
For instance:
For .NET 3.5:
万一这种情况发生在某人身上。我有一个类似的场景,我将基类转换为模板类(即 BaseView 到 BaseView)。我不断收到 InitializeComponent() 方法中的错误。我在 x:Class 基类型的 InitializeComponent() 调用中收到 null 异常错误。我能够通过从 XAML 定义中删除表单级事件来解决这些错误。如果我必须保留表单级事件,我需要将它们移动到 BaseView。
In case this happens to someone. I had a similar scenario where I converted my base class to a templated class (i.e. BaseView to BaseView). I kept receiving errors in the InitializeComponent() method. I was receiving the null exception error in the x:Class base type's InitializeComponent() call. I was able to resolve the errors by removing the form-level events from the XAML definition. If I had to keep the form-level events I would need to move them to BaseView.