0

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

通过使用 IsPressed 属性的 Multi 触发器,我正在更改按钮的背景颜色,但即使在按下按钮以显示按钮已被按下后,我也想保留背景颜色

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

1 回答 1

0

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

于 2013-04-30T15:09:43.420 回答