【问题标题】:How do I set Frame.Navigate to happen immediately with no transition?如何将 Frame.Navigate 设置为立即发生而没有过渡?
【发布时间】:2015-04-10 10:26:10
【问题描述】:

我正在开发作为 Windows 通用应用程序一部分的 Windows Phone 8.1 应用程序。按照 Windows 通用应用程序中extending splash screens 的教程,我将 App.xaml.cs 更改为替换

if (!rootFrame.Navigate(typeof(SplashPage), e.Arguments))
{
    throw new Exception("Failed to create splash page");
}

if (e.PreviousExecutionState != ApplicationExecutionState.Running)
{
    var extendedSplash = new SplashPage(e.SplashScreen);
    Window.Current.Content = extendedSplash;
}

但这意味着当我覆盖Window.Current.Content 时,我无法访问根框架。我想改用

SplashPage.SplashScreen = e.SplashScreen;
if (!rootFrame.Navigate(typeof(SplashPage), e.Arguments))
{
    throw new Exception("Failed to create splash page");
}

但现在页面过渡了。Frame.Navigate 有一个覆盖,它需要一个额外的 NavigationTransitionInfo 参数,通常设置为其子类之一:

  1. CommonNavigationTransitionInfo(即从右侧滚入);
  2. SlideNavigationTransitionInfo(即向上滑动);或
  3. ContinuumNavigationTransitionInfo(即短暂放大)。

(N.B. James Croft 有一个很好的 blog post 展示了这些转换。)

但对于初始屏幕扩展,我需要页面立即显示,而不需要过渡(就像用新页面实例覆盖 Window.Current.Content 一样)。

如何将Frame.Navigate 设置为立即发生而不进行转换?

【问题讨论】:

  • 我认为它应该可以工作,如果您禁用帧的默认转换 - 在 app.xaml.cs 文件中,其中创建了 rootFrame ,刚创建完,添加rootFrame.ContentTransitions = null;.
  • 太棒了。这已经在 App.xaml.cs 中,但它引导我进入 Frame.Navigated 事件,我可以在其中更改处理程序以仅在 NavigationEventArgs.SourcePageType != typeof(SplashPage) 时添加回过渡
  • 您也可以考虑禁用框架的过渡,并在需要时为 xaml 中的每个页面定义它们。

标签: windows-runtime windows-phone-8.1 win-universal-app


【解决方案1】:

对于那些想为 Windows 10 UWP 应用做同样事情的人,可以这样实现:

// Navigate to your first page without a transition 
Frame.Navigate(typeof(MainPage), null, new SuppressNavigationTransitionInfo());

根据this MSDN document.

【讨论】:

    【解决方案2】:

    我会尝试禁用默认 Frame.ContentTransitions,方法是在 App 中创建 rootFrame 之后将其设置为 null .xaml.cs 文件(不要忘记处理不同的事件 - Launched/ShareTarget/Activated - 如果需要):

    rootFrame.ContentTransitions = null
    

    一旦你这样做了,页面就不应该有过渡。然后,如果您愿意,您可以在特定情况下为 Frame 的内容带回或设置新的过渡,或单独为页面设置过渡,例如在 Page 的 XAML 中:

    <Page.Transitions>
        <TransitionCollection>
            <EntranceThemeTransition/>
        </TransitionCollection>
    </Page.Transitions>
    

    【讨论】:

    • 我在 Windows 10 通用应用程序中使用 WebView,动画导致“页面加载闪烁”。在 AppShell.xaml 中删除 解决了这个问题。
    猜你喜欢
    • 2015-04-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多