I have a project with WPF. How can I use Data Template and sub Data Template on it.
I have below class in my project.
public abstract Class X
public Class A: X
public Class B: X
public Class C: X
and use below code in XAML file:
<DataTemplate DataType="{x:Type A}">
...
</DataTemplate>
<DataTemplate DataType="{x:Type B}">
...
</DataTemplate>
<DataTemplate DataType="{x:Type C}">
...
</DataTemplate>
<DataTemplate DataType="{x:Type X}" x:Key="xdatatemplate">
...
<!-- use datatemplate of A,B or C --!>
...
</DataTemplate>
<ItemsControl ItemTemplate="{StaticResource xdatatemplate}"/>
I want to use xdatatemplate for Itemtemplate of my ItemsControl. ItemsSource items are of type A, B or C. and only part of my datatemplate is different between type A, type B and type C. How can I use A, B and C sub DataTemplate on X DataTemplate?
Can I use ItemTemplateSelector for this purpose?
Thanks in advance.
If xdatatemplate selects sub DataTemplate only by its DataType, then you can do it like this:
However, if you need more complex sub DataTemplate selection logic, you should use ContentTemplateSelector: