按钮的背景颜色在WPF的

时间:2013-04-30 12:02:34

标签: wpf-controls

如果按下按钮后如何保持按钮的背景颜色,现在我正在按下按钮的样式

通过使用IsPressed属性的多重触发器我正在改变按钮的背景颜色,但是我想保留背景颜色,即使按下按钮后显示按钮被按下

  <Style TargetType="{x:Type Button}" x:Key="Menubtn">
    <Setter Property="Cursor" Value="Hand"></Setter>
    <Setter Property="Height" Value="35"></Setter>
    <Setter Property="Width" Value="125"></Setter>
    <Setter Property="Margin" Value="10,0,0,0"></Setter>
    <Setter Property="FontWeight" Value="DemiBold"></Setter>
    <Setter Property="FontFamily" Value="Calibri"></Setter>
    <Setter Property="FontSize" Value="15"></Setter>
    <Setter Property="Foreground" Value="White"></Setter>        
    <Setter Property="VerticalAlignment" Value="Center"></Setter>
    <Setter Property="Background" Value="#FF0080D4"></Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <Border BorderThickness="1" Background="#FF0080D4"  x:Name="GridButton">
                    <Grid>
                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Width="Auto" />
                    </Grid>
                </Border>
                <ControlTemplate.Triggers>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsMouseOver" Value="True"></Condition>
                            <Condition Property="IsPressed" Value="True"></Condition>
                            <Condition Property="IsFocused" Value="True"></Condition>
                        </MultiTrigger.Conditions>
                        <Setter Property="Foreground" Value="#6D595C"></Setter>
                        <Setter Property="Background" TargetName="GridButton" Value="#EBEBEB"></Setter>
                    </MultiTrigger>
                    <MultiTrigger>
                        <MultiTrigger.Conditions>
                            <Condition Property="IsMouseOver" Value="false"></Condition>
                            <Condition Property="IsPressed" Value="false"></Condition>
                            <Condition Property="IsFocused" Value="false"></Condition>
                        </MultiTrigger.Conditions>
                        <Setter Property="Foreground" Value="White"></Setter>
                        <Setter Property="Background" TargetName="GridButton" Value="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=Background}" ></Setter>
                    </MultiTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>

        </Setter.Value>
    </Setter>      

1 个答案:

答案 0 :(得分:0)

我的按钮现在正在将其更改为切换按钮,感谢“CodeNaked”评论