2
我在這個問題的最後粘貼了一些xaml。它來自我的項目中的資源文件。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>
嗨德魯。你是否知道有任何工具可以幫助完成這樣的重構?類似於resharper如何在代碼中做它.. Cheers – Berryl 2009-10-07 02:16:58
@Berryl - 我還沒有看到任何工具,但我相信他們很快就會出現。對於想要試用ReSharper插件API的人來說,這可能是一個有趣的項目。 – 2009-10-07 05:57:20
@DrewNoakes我想這不會是明智的繼續等待:-) – itsho 2015-04-13 17:18:50