levanovd
levanovd

Reputation: 4165

How to specify two DataTemplates for single type?

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 templates (old templates supported editing, new ones - not).

Upvotes: 5

Views: 2112

Answers (2)

viky
viky

Reputation: 17669

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

Upvotes: 1

Jarek Kardas
Jarek Kardas

Reputation: 8455

you would need to use DataTemplateSelector (msdn link)

Upvotes: 2

Related Questions