我有 ResourceDicionaryIcon 我存储像 DrawingBrush 这样的图标。我想将画笔颜色从 {DynamicResource GreyBrush} 更改为允许我在控件模板按钮中选择颜色(与文本颜色相同)的颜色。
<DrawingBrush x:Key="icoEdit" Stretch="Uniform">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="{DynamicResource GreyBrush}" Geometry="F1 M 4.95279,30.227L 11.737,37.0113L 37.5279,11.2205L 30.7437,4.43622L 4.95279,30.227 Z "/>
<GeometryDrawing Brush="{DynamicResource GreyBrush}" Geometry="F1 M 31.7877,3.39215L 38.572,10.1764L 41.9641,6.78424L 35.1798,0L 31.7877,3.39215 Z "/>
<GeometryDrawing Brush="{DynamicResource GreyBrush}" Geometry="F1 M 10.6276,38.096L 0,41.9641L 3.86807,31.3365L 10.6276,38.096 Z "/>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
实际上,我在 Canvas 中像背景一样显示图标。但这不允许我选择颜色。有没有更好的解决方案我该怎么做?
<Canvas x:Name="canvas" (...) Background="{TemplateBinding Background}" />
编辑:
<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="grid" (...)>
(...)
<TextBlock Text="{TemplateBinding Content}" (...) Foreground="{TemplateBinding Foreground}"/>
<Canvas x:Name="canvas" (...) Background="{TemplateBinding Background}" (...)>
</Canvas>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Button x:Name="Button"
Style="{DynamicResource ButtonStyle}"
Foreground="#FF434341"
Background="{DynamicResource icoEdit}"
Content="BUTTON TEXT" (...)/>