In converting my treeview to use checkboxes, as in the article by Josh Smith, I find my working xaml code to use multiple HierarchicalDataTemplates of exactly the same format, but with different DataTypes.
Is there anyway to define a single static HierarchicalDataTemplate in XAML, but assign different datatypes where the xaml instantiates the objects?
Here are two working HierarchicalDataTemplates. The only diffence is in the DataType:
XAML
<HierarchicalDataTemplate
DataType="{x:Type r:ReportViewModel}"
ItemsSource="{Binding Children}"
>
<StackPanel Orientation="Horizontal">
<CheckBox
Focusable="False"
IsChecked="{Binding IsChecked}"
VerticalAlignment="Center"
/>
<ContentPresenter
Content="{Binding Name, Mode=OneTime}"
Margin="2,0"
/>
</StackPanel>
</HierarchicalDataTemplate>
<HierarchicalDataTemplate
DataType="{x:Type r:NetworkViewModel}"
ItemsSource="{Binding Children}"
>
<StackPanel Orientation="Horizontal">
<CheckBox
Focusable="False"
IsChecked="{Binding IsChecked}"
VerticalAlignment="Center"
/>
<ContentPresenter
Content="{Binding Name, Mode=OneTime}"
Margin="2,0"
/>
</StackPanel>
</HierarchicalDataTemplate>
Thanks for any help.
Addendum: I found a partial answer at How do I reuse a HierarchicalDataTemplate?
Unless someone has a better solution?