I have met 3 types using of eventtrigger

 

1. fetch from this link   (using XXControl.Trigger)

http://stackoverflow.com/questions/3870214/eventtrigger-with-setter-in-wpf

 

<Grid>
  <Grid.Triggers>
        <EventTrigger RoutedEvent="Button.Click" SourceName="btnFocusTrue">
            <BeginStoryboard Name="FocusTrueStoryboard">
                <Storyboard >
                    <BooleanAnimationUsingKeyFrames
                        Storyboard.TargetName="tb"
                        Storyboard.TargetProperty="(TextBox.Focusable)">
                        <DiscreteBooleanKeyFrame
                            KeyTime="00:00:01"
                            Value="True" />
                    </BooleanAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
        <EventTrigger RoutedEvent="Button.Click" SourceName="btnFocusFalse">
            <BeginStoryboard Name="FoucsFalseStoryboard">
                <Storyboard >
                    <BooleanAnimationUsingKeyFrames
                        Storyboard.TargetName="tb"
                        Storyboard.TargetProperty="(TextBox.Focusable)">
                        <DiscreteBooleanKeyFrame
                            KeyTime="00:00:01"
                            Value="False" />
                    </BooleanAnimationUsingKeyFrames>
                </Storyboard>
            </BeginStoryboard>
        </EventTrigger>
    </Grid.Triggers>
</Grid>

 

2. from this link    (using XXControl.Style   >>  Style.Trigger)

http://www.wpf-tutorial.com/styles/trigger-datatrigger-event-trigger/

<Window x:Class="WpfTutorialSamples.Styles.StyleTriggersSample"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="StyleTriggersSample" Height="100" Width="300">
    <Grid>
        <TextBlock Text="Hello, styled world!" FontSize="28" HorizontalAlignment="Center" VerticalAlignment="Center">
            <TextBlock.Style>
                <Style TargetType="TextBlock">
                    <Setter Property="Foreground" Value="Blue"></Setter>
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Foreground" Value="Red" />
                            <Setter Property="TextDecorations" Value="Underline" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </TextBlock.Style>
        </TextBlock>
    </Grid>
</Window>

 

 

 

3. using in <Resources>

 

        <Style x:Key="CbxDropDown" TargetType="ComboBox">
            <Style.Triggers>
                <EventTrigger RoutedEvent="KeyDown">
                    <BeginStoryboard Name="CBX_KD">
                        <Storyboard>
                            <BooleanAnimationUsingKeyFrames
                                    Storyboard.TargetProperty="IsDropDownOpen" >
                                <DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="True" />
                            </BooleanAnimationUsingKeyFrames>
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Style.Triggers>
        </Style>

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 olivermode 的頭像
    olivermode

    olivermode的部落格

    olivermode 發表在 痞客邦 留言(0) 人氣()