繁体   English   中英

WPF框架通过情节提要触发器

[英]WPF Frame triggers via storyboard

一般来说,我对C#/ WPF还是很陌生,所以很可能会丢失一些东西。

有没有一种方法可以通过会在Frame.Navigating事件上触发的情节Frame.Navigating来对Frame进行动画Frame.Navigating 我可以从中选择大多数常见的东西,例如Frame.Loaded而不是我Frame.Loaded的事件。

编辑:我想知道自定义RoutedEvent是解决此问题的最佳方法吗?

当用户单击按钮时,将Frame.Navigate方法并加载到新的Page中。

我想发生的是...

  • 单击按钮
  • (关键帧: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>

代码:

    Storyboard sb;
    private void Frame_Navigating(object sender, NavigatingCancelEventArgs e)
    {
        if (sb != null)
        {
            sb.Begin();
        }
    }

    private void Button_Click(object sender, RoutedEventArgs e)
    {
        sb = (Storyboard)Frm.Resources["SbKey"];
        Storyboard.SetTargetName(sb, "Frm");

        Frm.Navigate("Page1.xaml");         
    }

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM