C# 如何更改ContentControl中的路径填充颜色
我有很多形状需要在C# 如何更改ContentControl中的路径填充颜色,c#,wpf,C#,Wpf,我有很多形状需要在ResourceDictionary中重用。我的问题是,是否有比以下更好的方法来更改形状的填充颜色: style.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" Str
ResourceDictionary
中重用。我的问题是,是否有比以下更好的方法来更改形状的填充颜色:
style.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>
提前谢谢 定义样式资源:
<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>
定义样式资源:
<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>
谢谢,一如既往。你能告诉我直接使用样式和使用路径对象有什么区别,或者更好的做法是什么吗?简言之,样式是一种应用于特定类型元素的样式,路径是元素的实例。谢谢,一如既往。你能告诉我直接使用样式和使用路径对象有什么区别吗?或者更好的做法是什么?简言之,样式是一种应用于特定类型元素的样式,路径是元素的实例。