鼠标悬停在默认按钮上更改背景

Change background on mouse over for default button

在 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 , Example of Multi Trigger in 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>