我可以在 XAML(.NET 4 Framework 之前)中指定泛型类型吗? [英] Can I specify a generic type in XAML (pre .NET 4 Framework)?

查看:36
本文介绍了我可以在 XAML(.NET 4 Framework 之前)中指定泛型类型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 XAML 中,我可以声明一个 DataTemplate,以便在显示特定类型时使用该模板.例如,此 DataTemplate 将使用 TextBlock 来显示客户的姓名:

In XAML I can declare a DataTemplate so that the template is used whenever a specific type is displayed. For example, this DataTemplate will use a TextBlock to display the name of a customer:

<DataTemplate DataType="{x:Type my:Customer}">
    <TextBlock Text="{Binding Name}" />
</DataTemplate>

我想知道是否可以定义一个在 IList 出现时随时使用的 DataTemplate被陈列.因此,如果 ContentControl 的 Content 是 ObservableCollection;它将使用该模板.

I'm wondering if it's possible to define a DataTemplate that will be used any time an IList<Customer> is displayed. So if a ContentControl's Content is, say, an ObservableCollection<Customer> it would use that template.

是否可以使用 {x:Type} 标记扩展在 XAML 中声明像 IList 这样的泛型类型?

Is it possible to declare a generic type like IList in XAML using the {x:Type} Markup Extension?

推荐答案

不是开箱即用,不是;但也有一些有进取心的开发者这样做了.

Not out of the box, no; but there are enterprising developers out there who have done so.

微软的 Mike Hillberg 在这篇文章,例如.Google 当然还有其他的.

Mike Hillberg at Microsoft played with it in this post, for example. Google has others of course.

这篇关于我可以在 XAML(.NET 4 Framework 之前)中指定泛型类型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆