У меня есть некоторые xaml, вставленные в конце этого вопроса. Это из файла ресурсов в моем проекте.
HierarchicalDataTemplate и DataTemplate имеют одинаковую структуру. Есть ли способ извлечь общие части и ссылаться на них?
<HierarchicalDataTemplate DataType="{x:Type local:ChapterViewModel}"
x:Key="ChapterOutcomesTemplate"
ItemsSource="{Binding Path=Chapter.Outcomes}"
ItemTemplate="{StaticResource AssignedOutcomeTemplate}">
<StackPanel Orientation="Horizontal">
<Image Height="16"
Width="16"
Margin="0,0,0,0"
RenderOptions.BitmapScalingMode="NearestNeighbor"
SnapsToDevicePixels="True"
Source="{Binding Source={x:Static images:DocumentImages.Outcomes}}"
Visibility="{Binding IsOutcomesAssigned, Converter={StaticResource BooleanToVisibility}, Mode=OneWay}"
/>
<Image Height="16"
Width="16"
RenderOptions.BitmapScalingMode="NearestNeighbor"
SnapsToDevicePixels="True"
Margin="5,0,0,0"
Source="{Binding Source={x:Static images:DocumentImages.Chapter}}"
/>
<TextBlock Text="{Binding Chapter.Name}"
Margin="5,0,0,0" />
</StackPanel>
</HierarchicalDataTemplate>
<DataTemplate x:Key="ItemTemplate">
<StackPanel Orientation="Horizontal">
<Image Height="16"
Width="16"
Margin="0,0,0,0"
RenderOptions.BitmapScalingMode="NearestNeighbor"
SnapsToDevicePixels="True"
Source="{Binding Source={x:Static images:DocumentImages.Outcomes}}"
Visibility="{Binding IsOutcomesAssigned, Converter={StaticResource BooleanToVisibility}, Mode=OneWay}" />
<Image Height="16"
Width="16"
RenderOptions.BitmapScalingMode="NearestNeighbor"
SnapsToDevicePixels="True"
Margin="5,0,0,0"
Source="{Binding Source={x:Static images:DocumentImages.Chapter}}" />
<TextBlock Text="{Binding Chapter.Name}"
Margin="5,0,0,0" />
</StackPanel>
</DataTemplate>