简体   繁体   English

更改背景颜色禁用togglebutton

[英]Change background color disabled togglebutton

I have a toggle button in my Wpf application which is disabled in the code 我的Wpf应用程序中有一个切换按钮,在代码中被禁用

<ToggleButton IsEnabled="False"/>

How can i change the background of the disabled button. 如何更改禁用按钮的background

You can change the background brush of a ToggleButton in the template. 您可以在模板中更改ToggleButton的背景画笔。

Right click on your Control and -> Edit a copy. 右键单击您的控件,然后 - >编辑副本。

Name it and define where the Style should be (Ressource or local) There you see a Style and a Template 为它命名并定义样式应该在哪里(资源或本地)在那里你看到一个样式和一个模板

Sth. STH。 like this appear: 像这样出现:

    <Style x:Key="ToggleButtonStyle1" TargetType="{x:Type ToggleButton}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Themes:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" RenderDefaulted="{TemplateBinding Button.IsDefaulted}" SnapsToDevicePixels="True">
                        <ContentPresenter ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Themes:ButtonChrome>
                    <ControlTemplate.Triggers>
                       <Trigger Property="IsKeyboardFocused" Value="True">
                            <Setter Property="RenderDefaulted" TargetName="Chrome" Value="True"/>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter Property="RenderPressed" TargetName="Chrome" Value="True"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="#FFADADAD"/>
                            <Setter Property="Background" Value="green"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

In the Trigger "IsEnabled" can you set the new Brush directly or via Binding Value="{StaticResource MyBrush}" 在Trigger“IsEnabled”中你可以直接设置新的Brush还是通过Binding Value="{StaticResource MyBrush}"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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