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

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

问题描述

在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中;客户&GT;被显示。所以,如果一个ContentControl中的内容是,比如说,一个ObservableCollection&LT;客户&GT;它会使用该模板。

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:类型}在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.

麦克Hillberg在微软和它嬉戏在这个帖子,例如。谷歌有别人当然。

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

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

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