C# 将SolidColorBrush的颜色绑定到按钮的背景色
我用下面的代码创建了一个自定义圆角按钮,但是颜色按钮没有遵循按钮的背景属性,所以我必须为按钮的每种颜色创建新样式 如何将SolidColorBrush颜色绑定到按钮背景色C# 将SolidColorBrush的颜色绑定到按钮的背景色,c#,wpf,C#,Wpf,我用下面的代码创建了一个自定义圆角按钮,但是颜色按钮没有遵循按钮的背景属性,所以我必须为按钮的每种颜色创建新样式 如何将SolidColorBrush颜色绑定到按钮背景色 <Style x:Key="RoundedButton" TargetType="Button"> <Setter Property="Template"> <Setter.Value> <Cont
<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>