开发者

How to specify two DataTemplates for single type?

开发者 https://www.devze.com 2022-12-13 00:08 出处:网络
I defined in XAML DataTemplate for my own type. <DataTemplate DataType=\"{x:Type MyType}\"> ... </DataTemplate>

I defined in XAML DataTemplate for my own type.

<DataTemplate DataType="{x:Type MyType}">
    ...
</DataTemplate>

Now I want to add one more template for the same type in the same scope. How would I choose then which of templates to use in concrete ItemsControl?

Background:

I have ItemsControl that displays objects of different types (derived from one base class of course) in different way depending on the item's type. So I've specified unnamed data templates for each type. Now I need to show the same data but with new tem开发者_StackOverflow社区plates (old templates supported editing, new ones - not).


you would need to use DataTemplateSelector (msdn link)


you can do it by using DataTemplateSelector, Check this for details about how to use DataTemplateSelector:

http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/5b4db370-095e-4233-9d89-5dd8082fd474

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号