gpt4 book ai didi

wpf - 如何在 XAML 中指定泛型类型参数

转载 作者:行者123 更新时间:2023-12-03 03:35:58 27 4
gpt4 key购买 nike

我的 MVP - PRISM WPF 应用程序有一个 BaseView。现在出于某种原因,我们考虑将 _presenter 作为 BaseView 中的模板化字段。

之前我的 View xaml 表示为

<base:BaseView xamlns:base="clr address of the dll which had BaseView" >

</base:BaseView>

现在我已经更改了 BaseViewBaseView<TPresenter>,那么我该如何编写Xaml呢?

最佳答案

.NET 4 Framework 和 XAML 2009 开始您就可以做到这一点。请参阅Generics in XAML在 MSDN 上

例如:

<my:BusinessObject x:TypeArguments="x:String,x:Int32"/>

对于 .NET 3.5:

For XAML 2006 usage when specifically targeting WPF, x:Class must also be provided on the same element as x:TypeArguments, and that element must be the root element in a XAML document. The root element must map to a generic type with at least one type argument. An example is PageFunction.

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.

关于wpf - 如何在 XAML 中指定泛型类型参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7573712/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com