Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过故事板触发WPF帧_C#_Wpf_Events_Storyboard_Blend - Fatal编程技术网

C# 通过故事板触发WPF帧

C# 通过故事板触发WPF帧,c#,wpf,events,storyboard,blend,C#,Wpf,Events,Storyboard,Blend,一般来说,我对C#/WPF还很陌生,所以很可能我遗漏了什么 有没有办法通过将在帧上触发的故事板来设置帧的动画。导航事件?我可以从中选择的大多数常见事件,例如Frame.Loaded不是我所关注的事件 编辑:我想知道定制路由事件是实现这一点的最佳方式吗 当用户单击按钮时,将调用Frame.Navigate方法并加载到新页面中 我希望发生的是 按钮被点击 (关键帧:0.1s)-帧从100-0不透明度淡入 (关键帧:0.15s)-使用变换将帧移出画布 (关键帧:0.2s)-帧移回到屏幕上,不透明度回

一般来说,我对C#/WPF还很陌生,所以很可能我遗漏了什么

有没有办法通过将在
帧上触发的故事板来设置
帧的动画。导航
事件?我可以从中选择的大多数常见事件,例如
Frame.Loaded
不是我所关注的事件

编辑:我想知道定制路由事件是实现这一点的最佳方式吗

当用户单击按钮时,将调用
Frame.Navigate
方法并加载到新页面中

我希望发生的是

  • 按钮被点击
  • (关键帧:0.1s)-帧从100-0不透明度淡入
  • (关键帧:0.15s)-使用变换将帧移出画布
  • (关键帧:0.2s)-帧移回到屏幕上,不透明度回到100%
  • 页面已加载

这将为您解决问题

<Frame x:Name="Frm" Width="499" Height="248" Content="Frame"  Navigating="Frame_Navigating_1" BorderThickness="2" BorderBrush="#FF21BD9A">
    <Frame.RenderTransform>
        <TranslateTransform x:Name="TransTrfm" />
    </Frame.RenderTransform>
    <Frame.Resources>
        <Storyboard x:Key="SbKey">
            <DoubleAnimationUsingKeyFrames  Storyboard.TargetProperty="Opacity">
                <DoubleAnimationUsingKeyFrames.KeyFrames>
                    <LinearDoubleKeyFrame KeyTime="0:0:0" Value="1.0"/>
                    <LinearDoubleKeyFrame KeyTime="0:0:0.1" Value="0"/>
                </DoubleAnimationUsingKeyFrames.KeyFrames>
            </DoubleAnimationUsingKeyFrames>

            <DoubleAnimationUsingKeyFrames BeginTime="0:0:0.15" Storyboard.TargetProperty="X" Storyboard.TargetName="TransTrfm">
                <DoubleAnimationUsingKeyFrames.KeyFrames>
                    <LinearDoubleKeyFrame  KeyTime="0:0:0" Value="0.0" />
                    <LinearDoubleKeyFrame  KeyTime="0:0:0.17" Value="-1000.0" />
                    <LinearDoubleKeyFrame  KeyTime="0:0:0.2" Value="0.0" />
                </DoubleAnimationUsingKeyFrames.KeyFrames>
            </DoubleAnimationUsingKeyFrames>

            <DoubleAnimationUsingKeyFrames BeginTime="0:0:0.35" Storyboard.TargetProperty="Opacity">
                <DoubleAnimationUsingKeyFrames.KeyFrames>
                    <LinearDoubleKeyFrame KeyTime="0:0:0" Value="1.0"/>
                </DoubleAnimationUsingKeyFrames.KeyFrames>
            </DoubleAnimationUsingKeyFrames>

        </Storyboard>
    </Frame.Resources>
</Frame>

您还可以尝试使用
ControlStoryboardAction
行为和
ChangePropertyAction
行为来避免代码落后。

这将为您提供帮助

<Frame x:Name="Frm" Width="499" Height="248" Content="Frame"  Navigating="Frame_Navigating_1" BorderThickness="2" BorderBrush="#FF21BD9A">
    <Frame.RenderTransform>
        <TranslateTransform x:Name="TransTrfm" />
    </Frame.RenderTransform>
    <Frame.Resources>
        <Storyboard x:Key="SbKey">
            <DoubleAnimationUsingKeyFrames  Storyboard.TargetProperty="Opacity">
                <DoubleAnimationUsingKeyFrames.KeyFrames>
                    <LinearDoubleKeyFrame KeyTime="0:0:0" Value="1.0"/>
                    <LinearDoubleKeyFrame KeyTime="0:0:0.1" Value="0"/>
                </DoubleAnimationUsingKeyFrames.KeyFrames>
            </DoubleAnimationUsingKeyFrames>

            <DoubleAnimationUsingKeyFrames BeginTime="0:0:0.15" Storyboard.TargetProperty="X" Storyboard.TargetName="TransTrfm">
                <DoubleAnimationUsingKeyFrames.KeyFrames>
                    <LinearDoubleKeyFrame  KeyTime="0:0:0" Value="0.0" />
                    <LinearDoubleKeyFrame  KeyTime="0:0:0.17" Value="-1000.0" />
                    <LinearDoubleKeyFrame  KeyTime="0:0:0.2" Value="0.0" />
                </DoubleAnimationUsingKeyFrames.KeyFrames>
            </DoubleAnimationUsingKeyFrames>

            <DoubleAnimationUsingKeyFrames BeginTime="0:0:0.35" Storyboard.TargetProperty="Opacity">
                <DoubleAnimationUsingKeyFrames.KeyFrames>
                    <LinearDoubleKeyFrame KeyTime="0:0:0" Value="1.0"/>
                </DoubleAnimationUsingKeyFrames.KeyFrames>
            </DoubleAnimationUsingKeyFrames>

        </Storyboard>
    </Frame.Resources>
</Frame>

您还可以尝试使用
ControlStoryboardAction
行为和
ChangePropertyAction
行为来避免代码隐藏。

看这里:在我看来,一个明显的选择是,您的按钮开始动画而不是导航,并根据动画的状态触发导航。但这是一个相当模糊的轮廓;不可能确切地知道在你的情况下什么最有效。如果没有很好地展示您所做的尝试,这个问题就太广泛了,无法在这里得到合理的回答。看这里:在我看来,一个明显的选择是,您的按钮开始动画而不是导航,并根据动画的状态触发导航。但这是一个相当模糊的轮廓;不可能确切地知道在你的情况下什么最有效。如果你没有很好地展示你所做的尝试,这个问题就太宽泛了,无法在这里得到合理的回答。