簡體   English   中英

將SolidColorBrush的顏色綁定到Button的背景色

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM