![](/img/trans.png)
[英]Unable to bind property with color attribute of SolidColorBrush in xaml
[英]Bind color of SolidColorBrush to background color of Button
我用以下代码创建了一个自定义的圆形按钮,但是颜色按钮没有遵循按钮的Background属性,因此我必须为按钮的每种颜色创建新样式。
如何将SolidColorBrush颜色绑定到按钮背景色?
<Style x:Key="RoundedButton" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Rectangle RadiusX="6" RadiusY="6">
<Rectangle.Fill>
<SolidColorBrush Color="BUTTON BACKGROUND"/>
</Rectangle.Fill>
</Rectangle>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
按钮的背景已经是画笔。 无需创建另一个:
<ControlTemplate TargetType="Button">
<Grid>
<Rectangle RadiusX="6" RadiusY="6" Fill="{TemplateBinding Background}"/>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</ControlTemplate>
您可能必须使用一种方法DataBinding
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.