如何在窗口加载时防止故事板自动播放?我无法做到

时间:2015-08-09 15:41:30

标签: c# wpf storyboard mouseevent blend

我有4个带有动画的故事板。 我想要的是防止故事板在加载窗口时自动播放。我希望它们只在窗口内单击鼠标时播放。 我在一个故事板上尝试了以下内容:

private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {

        this.target2animation_BeginStoryboard.Storyboard.Stop();

    }

private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.target2animation_BeginStoryboard.Storyboard.Begin();
        }

它不起作用。它在窗口加载时播放一次。我甚至尝试过Freeze,Pause而不是Stop。仍然没有奏效。

然而,如果我点击,故事板总是从头开始,所以鼠标点击事件正在发挥作用。

请帮忙!

这是target2animate storyboard的代码(通过表达式混合创建)

<Storyboard x:Key="target2animation" RepeatBehavior="0:0:10">
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="ellipse">
            <EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="35">
                <EasingDoubleKeyFrame.EasingFunction>
                    <ElasticEase EasingMode="EaseOut" Springiness="5" Oscillations="2"/>
                </EasingDoubleKeyFrame.EasingFunction>
            </EasingDoubleKeyFrame>
            <EasingDoubleKeyFrame KeyTime="0:0:1.3" Value="-6">
                <EasingDoubleKeyFrame.EasingFunction>
                    <ElasticEase EasingMode="EaseInOut" Oscillations="2" Springiness="2"/>
                </EasingDoubleKeyFrame.EasingFunction>
            </EasingDoubleKeyFrame>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="ellipse">
            <EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="3">
                <EasingDoubleKeyFrame.EasingFunction>
                    <ElasticEase EasingMode="EaseOut" Springiness="5" Oscillations="2"/>
                </EasingDoubleKeyFrame.EasingFunction>
            </EasingDoubleKeyFrame>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="txbTarget2">
            <EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="35">
                <EasingDoubleKeyFrame.EasingFunction>
                    <ElasticEase EasingMode="EaseOut" Oscillations="2" Springiness="5"/>
                </EasingDoubleKeyFrame.EasingFunction>
            </EasingDoubleKeyFrame>
            <EasingDoubleKeyFrame KeyTime="0:0:1.3" Value="-5">
                <EasingDoubleKeyFrame.EasingFunction>
                    <ElasticEase EasingMode="EaseInOut" Oscillations="2" Springiness="2"/>
                </EasingDoubleKeyFrame.EasingFunction>
            </EasingDoubleKeyFrame>
        </DoubleAnimationUsingKeyFrames>
        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="txbTarget2">
            <EasingDoubleKeyFrame KeyTime="0:0:0.8" Value="4">
                <EasingDoubleKeyFrame.EasingFunction>
                    <ElasticEase EasingMode="EaseOut" Oscillations="2" Springiness="5"/>
                </EasingDoubleKeyFrame.EasingFunction>
            </EasingDoubleKeyFrame>
            <EasingDoubleKeyFrame KeyTime="0:0:1.3" Value="5">
                <EasingDoubleKeyFrame.EasingFunction>
                    <ElasticEase EasingMode="EaseInOut" Oscillations="2" Springiness="2"/>
                </EasingDoubleKeyFrame.EasingFunction>
            </EasingDoubleKeyFrame>
        </DoubleAnimationUsingKeyFrames>
    </Storyboard>

0 个答案:

没有答案