gpt4 book ai didi

c# - 应用程序暂停时不会调用 OnNavigatedFrom

转载 作者:行者123 更新时间:2023-11-30 20:46:24 25 4
gpt4 key购买 nike

今天我遇到了一个奇怪的问题 - 似乎在我的设备上 (v. 8.10.14203.306) OnNavigatedFrom 事件在应用程序暂停时没有被调用。据我记得不久前它工作正常,而且非常好 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);
}

当有正常的导航(例如通过后退按钮)时,事件被触发,但当应用程序被挂起时不再触发 - 无论是在 Debug模式还是 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# - 应用程序暂停时不会调用 OnNavigatedFrom,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27055521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com