WPF入门基础1——样式、触发器

1.样式
<Style x:Key="myStyle" TargetType="Button" >
            <Setter Property="Foreground" Value="Green"></Setter>
            <Setter Property="FontSize" Value="30"></Setter>
        </Style>

2.触发器

2.1trigger

<Style x:Key="myStyle" TargetType="Button" >
            <Setter Property="Foreground" Value="Green"></Setter>
            <Setter Property="FontSize" Value="30"></Setter>
            <Style.Triggers>
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Width" Value="200"/>
                </Trigger>
                <Trigger Property="IsMouseOver" Value="False">
                    <Setter Property="Width" Value="400"/>
                </Trigger>
            </Style.Triggers>
        </Style>

2.2 MultiTrigger

   <Style x:Key="myStyle" TargetType="Button" >
            <Setter Property="Foreground" Value="Green"></Setter>
            <Setter Property="FontSize" Value="30"></Setter>
            <Style.Triggers>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="IsMouseOver" Value="true"/>
                        <Condition Property="IsFocused" Value="true"/>
                    </MultiTrigger.Conditions>
                    <MultiTrigger.Setters>
                        <Setter Property="Foreground" Value="Yellow"/>
                    </MultiTrigger.Setters>
                </MultiTrigger>
            </Style.Triggers>
        </Style>

2.3 EventTrigger   (经常与动画配合使用)

<Style x:Key="myStyle1" TargetType="Button" >
            <Setter Property="Foreground" Value="Green"></Setter>
            <Setter Property="FontSize" Value="30"></Setter>
            <Style.Triggers>
                <EventTrigger RoutedEvent="Mouse.MouseEnter">
                    <EventTrigger.Actions>
                        <BeginStoryboard>
                            <Storyboard>
                                <DoubleAnimation Duration="0:0:0.2"  Storyboard.TargetProperty="FontSize" To="40">

                                </DoubleAnimation>
                            </Storyboard>
                        </BeginStoryboard>
                    </EventTrigger.Actions>
                </EventTrigger>
            </Style.Triggers>
        </Style>

  

 

posted @ 2023-03-31 15:21  MrKing&  阅读(70)  评论(0编辑  收藏  举报