本地计算机上的 UWP 慢退按钮
UWP Slow back button on Local Machine
我在写Windows10万能App,需要添加普通方法
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;
}
...在我的
App.xaml.cs
这将处理设备的后退按钮功能。
我在这里使用它:
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();
}
它工作正常,但问题是当我在本地计算机上构建和 运行 并使用后退按钮在页面之间导航时,它需要大约 5000 - 6000 毫秒(5-6 秒)才能导航到上一页。
我调试的时候,延迟时间:
if (rootFrame.CanGoBack && e.Handled == false)
{
e.Handled = true;
rootFrame.GoBack();
}
//debug
int stop = 0;
rootFrame.GoBack();和调试变量 "stop" 是 5,778 毫秒....,当我 运行 它在移动模拟器或移动设备上延迟时间减少到 ~100ms
如果有人能提供帮助,我将不胜感激。
谢谢
我找到了导致延迟的原因,这是我的 MainPage 文件中的两个 SQL 事务方法,它们用于从 SQLite 数据库文件中获取大量数据。每次调用分页时都会调用它们。 (放置在页面构造函数中)。我将它们分开 class 移动,一切似乎都很好。
我在写Windows10万能App,需要添加普通方法
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;
}
...在我的
App.xaml.cs
这将处理设备的后退按钮功能。
我在这里使用它:
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();
}
它工作正常,但问题是当我在本地计算机上构建和 运行 并使用后退按钮在页面之间导航时,它需要大约 5000 - 6000 毫秒(5-6 秒)才能导航到上一页。
我调试的时候,延迟时间:
if (rootFrame.CanGoBack && e.Handled == false)
{
e.Handled = true;
rootFrame.GoBack();
}
//debug
int stop = 0;
rootFrame.GoBack();和调试变量 "stop" 是 5,778 毫秒....,当我 运行 它在移动模拟器或移动设备上延迟时间减少到 ~100ms
如果有人能提供帮助,我将不胜感激。 谢谢
我找到了导致延迟的原因,这是我的 MainPage 文件中的两个 SQL 事务方法,它们用于从 SQLite 数据库文件中获取大量数据。每次调用分页时都会调用它们。 (放置在页面构造函数中)。我将它们分开 class 移动,一切似乎都很好。