c# - 当应用程序暂停时,不会调用 OnNavigateFrom

标签 c# windows-runtime windows-phone-8.1

今天我遇到了奇怪的问题 - 似乎在我的设备(v. 8.10.14203.306)上,当应用程序暂停时,OnNavieratedFrom 事件没有被调用。据我记得前段时间它工作正常,而且完全正确as documentation stays :

Note On Windows Phone, OnNavigatedFrom() is called when the app is suspended. OnNavigatedTo() is not called when the app is resumed.

我尝试了一个简单的示例( available at GitHub ):

protected override void OnNavigatedFrom(NavigationEventArgs e)
{
    this.navigationHelper.OnNavigatedFrom(e);
    Debug.WriteLine("Navigation");
    this.Background = new SolidColorBrush(Colors.Red);
}

当正常导航(例如通过后退按钮)时,事件会被触发,但当应用程序暂停时(无论是在调试还是 Release模式下)都不会再触发。我还检查了 Suspending 事件是否被触发,结果是:

// uncomment this to check if app is being suspended
App.Current.Suspending += (sender, e) => this.Background = new SolidColorBrush(Colors.Blue);

我错过了什么吗?

最佳答案

我唯一可以建议的是确保您调用 Frame.GetNavigationState从您的 Application.Suspending 处理程序中(这通常由 SuspensionManager.SaveAsync 完成)。根据文档:

Calling this method will call Page.OnNavigatedFrom for the current page using NavigationMode.Forward. GetNavigationState is usually called when the application is being suspended, so the current page is navigated away from.

关于c# - 当应用程序暂停时,不会调用 OnNavigateFrom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27055521/

相关文章:

c# - 禁用 DataGridView 中的自动添加行

c# - Windows Phone WEB API 通过 HttpClient 发布返回 404 错误

c# - 在 WinRT 中绑定(bind)到 XAML 中的 DynamicObjects

c# - 如何找到抛出 EETypeLoadException 的原因?

javascript - 获取 WebView 的内容高度 - Windows Phone 8.1

c# - 如何以MVVM方式为Windows Universal App实现条件导航/重定向

c# - MemoryMappedFile 不适用于 2 个进程?

c# - Autofac 已下载,我可以访问生成器方法但不能访问 RegisterControllers 方法

C# 在 Swift 中使用等效语句

c# - Windows Phone 8.1 WinRT 应用程序中的自定义消息框