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>

 

posted @ 2019-10-28 22:15  ARM830  阅读(1314)  评论(0编辑  收藏  举报