更改默认按钮的鼠标背景

本文关键字:鼠标 背景 默认按钮 | 更新日期: 2023-09-27 18:02:37

在WPF应用程序中,我想在MouseOver上更改ButtonBackGround。触发器IsDefaultIsMouseOver已经调整。是否有可能定义单独的触发器,对IsDefaultIsMouseOver触发器都起作用?

<ControlTemplate.Triggers>
    <Trigger Property="IsDefault" Value="True">
        <Setter Property="Background" Value="#1BA1E2" />
    </Trigger>
    <Trigger Property="IsMouseOver" Value="True">
        <Setter Property="Background" Value="#9A9EA1" />
    </Trigger>
    <Trigger ??? Property="IsDefault" Value="True" && Property="IsMouseOver" Value="True" />
        <Setter Property="Background" Value="#9A9E88"/>    
    </Trigger>
</ControlTemplate.Triggers>

更改默认按钮的鼠标背景

您可以使用MultiTrigger, MultiTrigger在WPF中的示例。这样的:

<Window.Resources>
    <Style x:Key="Multi" TargetType="{x:Type Button}" >
        <Style.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsDefault" Value="True"></Condition>
                    <Condition Property="IsMouseOver" Value="True"></Condition>
                </MultiTrigger.Conditions>
                <MultiTrigger.Setters>
                    <Setter Property="Background" Value="White" ></Setter>
                </MultiTrigger.Setters>
            </MultiTrigger>
        </Style.Triggers>
    </Style>
 </Window.Resources>
 <Grid>
    <Button Style="{StaticResource Multi}"></Button>
 </Grid>