我有很多形状需要在ResourceDictionary
中重复使用。我的问题基本上是否有更好的方法来改变形状的填充颜色而不是以下:
Styles.xaml
<Path x:Key="ShapeTick"
Width="36"
Height="29.17"
Data="M36.068-15.439l1.993,2.263L14.393,13.731,2.061-.3,4.053-2.564,14.393,9.154Z"
Stretch="Fill" />
View.xaml
<ContentControl Content="{Binding Source={StaticResource ShapeTick}}">
<ContentControl.Resources>
<Style TargetType="Path">
<Setter Property="Fill" Value="{StaticResource SGreen}"/>
</Style>
</ContentControl.Resources>
</ContentControl>
提前致谢!
答案 0 :(得分:1)
定义样式资源:
<Style x:Key="PathStyle" TargetType="Path">
<Setter Property="Width" Value="36" />
<Setter Property="Height" Value="29.17" />
<Setter Property="Data" Value="M36.068-15.439l1.993,2.263L14.393,13.731,2.061-.3,4.053-2.564,14.393,9.154Z" />
<Setter Property="Stretch" Value="Fill" />
</Style>
...并将此一个应用于具有不同颜色的Path
元素:
<Path Style="{StaticResource PathStyle}" Fill="Red" />
<Path Style="{StaticResource PathStyle}" Fill="Blue" />