WPF 使用EventTrigger时设置SouceName技巧

Posted lonelyxmas

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF 使用EventTrigger时设置SouceName技巧相关的知识,希望对你有一定的参考价值。

原文:WPF 使用EventTrigger时设置SouceName技巧

使用情节触发器时,如果有触发源/触发源控件时可以将情节触发器放置最顶级的面板控件的触发器中。

通过blend这个神器真的是可以学到不少东西。

技术图片

代码:

技术图片
//情节动画放置于顶级控制面板
<Widnow.Resources>
  <Storyboard x:Key="OnMouseLeftButtonUpForGrid">
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="dockPanel">
                <EasingDoubleKeyFrame KeyTime="0" Value="0.675"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="0.896"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="0.997"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="dockPanel">
                <EasingDoubleKeyFrame KeyTime="0" Value="0.638"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="0.835"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="0.991"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="dockPanel">
                <EasingDoubleKeyFrame KeyTime="0" Value="111"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="35.25"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="0.75"/>
            </DoubleAnimationUsingKeyFrames>
            <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="dockPanel">
                <EasingDoubleKeyFrame KeyTime="0" Value="-66"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.4" Value="-30"/>
                <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="-1.5"/>
            </DoubleAnimationUsingKeyFrames>
        </Storyboard>
</Window.Resources>
<Window.Triggers>
 <EventTrigger RoutedEvent="UIElement.MouseLeftButtonUp" SourceName="grid1">
            <BeginStoryboard x:Name="OnMouseLeftButtonUpForGrid_BeginStoryboard" Storyboard="{StaticResource OnMouseLeftButtonUpForGrid}"/>
        </EventTrigger>
</Window.Triggers>
技术图片

 

技术图片
<DockPanel x:Name="dockPanel" RenderTransformOrigin="0.5,0.5">
            <DockPanel.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </DockPanel.RenderTransform>
            <Grid x:Name="grid1" Height="40" DockPanel.Dock="Top" Background="Red">
                <Button x:Name="button" HorizontalAlignment="Right" Content="ccc"/>
            </Grid>
            <Grid x:Name="grid" Height="40"    VerticalAlignment="Top" DockPanel.Dock="Top" Background="Green" RenderTransformOrigin="0.5,0.5">
            </Grid>
        </DockPanel>
技术图片

 

以上是关于WPF 使用EventTrigger时设置SouceName技巧的主要内容,如果未能解决你的问题,请参考以下文章

WPF 使用EventTrigger设置Item的IsSelected选项

WPF 使用EventTrigger设置Item的IsSelected选项

WPF 通过EventTrigger修改鼠标样式

WPF EventTrigger并不总是触发

wpf 触发器理解

WPF编游戏系列 之六 动画效果