首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >本地机器上的UWP慢速后退按钮

本地机器上的UWP慢速后退按钮
EN

Stack Overflow用户
提问于 2016-10-12 12:24:32
回答 1查看 187关注 0票数 2

我正在编写Windows 10通用应用程序,我需要添加普通方法

代码语言:javascript
复制
    private void OnBackRequested(object sender, BackRequestedEventArgs e)
    {
        Frame rootFrame = Window.Current.Content as Frame;


        if (rootFrame == null)
            return;

        if (rootFrame.CanGoBack && e.Handled == false)
        {
            e.Handled = true;
            rootFrame.GoBack();
        }

        //debug
        int stop = 0;
    }

...in my

App.xaml.cs

这将处理设备的后退按钮功能。

我在这里用它:

代码语言:javascript
复制
       protected override void OnLaunched(LaunchActivatedEventArgs e)
    {
        Frame rootFrame = Window.Current.Content as Frame;

        // Do not repeat app initialization when the Window already has content,
        // just ensure that the window is active
        if (rootFrame == null)
        {
            // Create a Frame to act as the navigation context and navigate to the first page
            rootFrame = new Frame();

            rootFrame.NavigationFailed += OnNavigationFailed;
            rootFrame.Navigated += OnNavigated;

            if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                // TODO: Load state from previously suspended application
            }

            // Place the frame in the current Window
            Window.Current.Content = rootFrame;

            // Register a handler for BackRequested events and set the
            // visibility of the Back button
            SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested;

            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility =
                rootFrame.CanGoBack ?
                AppViewBackButtonVisibility.Visible :
                AppViewBackButtonVisibility.Collapsed;
        }

        if (rootFrame.Content == null)
        {
            // When the navigation stack isn't restored navigate to the first page,
            // configuring the new page by passing required information as a navigation
            // parameter
            rootFrame.Navigate(typeof(MainPage), e.Arguments);
        }

        // Ensure the current window is active
        Window.Current.Activate();
    }

它可以正常工作,但问题是当我在本地机器上构建并运行并使用Back Button在页面之间导航时,它需要大约5000到6000 ms (5-6秒)才能导航到上一页。

当我调试它时,延迟:

代码语言:javascript
复制
    if (rootFrame.CanGoBack && e.Handled == false)
    {
        e.Handled = true;
        rootFrame.GoBack();
    }

    //debug
    int stop = 0;

rootFrame.GoBack();并且调试变量"stop“为5,778 ms.,当我在移动仿真程序或移动设备上运行它时,延迟时间缩短到~100 ms。

我会感激是有人能帮助我。谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-13 07:20:47

我发现了导致延迟的原因,这是我的MainPage文件中的两个SQLite方法,用于从SQLite数据库文件获取很多数据。每次传呼时都叫他们。(放置在页面构造函数中)。我把它们分开上课,一切似乎都很好。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39998564

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档