我有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" (...)/>
答案 0 :(得分:2)
我猜你应该把你的Binding
倒是这样:
<GeometryDrawing Brush="{Binding Background, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type Canvas}}}" Geometry="F1 M 4.95279,30.227L 11.737,37.0113L 37.5279,11.2205L 30.7437,4.43622L 4.95279,30.227 Z "/>
这里我绑定Brush
到上/父元素
我现在没有Visual Studio来检查这个问题。如果我错了,请纠正我