'How to set a DataTemplate with one x:Key and multiple DataType?
I want to define multiple DataTemplate that can be selected based on DataType, and switch in Style. How can I get this effect using only XAML code? Or impossible?
UPDATE: Sorry, my fault, I didn't write clearly. I can't set default because I want to be able to switch views.
<ListView.Resources>
<DataTemplate x:Key="xkey">
<...... for DataType="{x:Type local:typea}" />
<...... for DataType="{x:Type local:typeb}" />
</DataTemplate>
<DataTemplate x:Key="xkey2">
<...... for DataType="{x:Type local:typea}" />
<...... for DataType="{x:Type local:typeb}" />
</DataTemplate>
</ListView.Resources>
<ListView.Style>
<Style TargetType="ListView">
<Style.Triggers>
<DataTrigger ....>
<Setter Property="ItemTemplate" Value="{StaticResource xkey}"/>
</DataTrigger>
<DataTrigger ....>
<Setter Property="ItemTemplate" Value="{StaticResource xkey2}"/>
</DataTrigger>
<DataTrigger ...>
<Setter Property="View" Value=... />
</DataTrigger>
</Style.Triggers>
</Style>
</ListView.Style>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
