简体   繁体   English

将SolidColorBrush的颜色绑定到Button的背景色

[英]Bind color of SolidColorBrush to background color of Button

I created a custom rounded button with following code But the color button doesn't follow the Background property of button so i have to create new style for each color of button. 我用以下代码创建了一个自定义的圆形按钮,但是颜色按钮没有遵循按钮的Background属性,因此我必须为按钮的每种颜色创建新样式。

How can i bind SolidColorBrush Color to Button Background color ? 如何将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>

The Button's Background is already a Brush. 按钮的背景已经是画笔。 No need to create another one: 无需创建另一个:

<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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM