大前端

前端学习之家-大前端

WPF 触发器

简单触发器

<Window.Resources>
    <Style x:Key="DefaultBtn" TargetType="Button">
        <Style.Triggers>
            <!--类似hover-->
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Foreground" Value="Blue"></Setter>
            </Trigger>
        </Style.Triggers>
    </Style>
</Window.Resources>
<Grid>
    <StackPanel>
        <Button Width="100" Height="100" Content="heihei" Style="{StaticResource DefaultBtn}" />
    </StackPanel>
</Grid>

在这里插入图片描述
多条件触发器

当鼠标悬停并且被选中时触发

<Window.Resources>
    <Style x:Key="DefaultBtn" TargetType="Button">
        <Style.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsMouseOver" Value="True"></Condition>
                    <Condition Property="IsFocused" Value="True"></Condition>
                </MultiTrigger.Conditions>
                <MultiTrigger.Setters>
                    <Setter Property="Foreground" Value="Red"></Setter>
                </MultiTrigger.Setters>
            </MultiTrigger>
        </Style.Triggers>
    </Style>
</Window.Resources>
<Grid>
    <StackPanel>
        <Button Width="100" Height="100" Content="heihei" Style="{StaticResource DefaultBtn}" />
    </StackPanel>
</Grid>

发表评论:

Copyright Your WebSite.Some Rights Reserved.