手机唤醒时Application_Activated中的代码未运行
我已经对Windows Phone应用程序的生命周期进行了一些研究,并且我已经收集到当应用程序仍在运行时手机被锁定,并且您解锁手机时,App.xaml中调用了“Application_Activated”function。 cs文件。
// Code to execute when the application is activated (brought to foreground) // This code will not execute when the application is first launched private void Application_Activated(object sender, ActivatedEventArgs e) { //Code to run MessageBox.Show("Hello there!"); }
现在在上面的例子中,简单的’MessageBox’调用没有运行。 就像我说的,如果您的应用程序正在运行并且您锁定了手机,然后解锁了手机,则上述代码可能会运行,在这种情况下,只要您解锁手机就会显示一个MessageBox。
真的很感激任何帮助! 谢谢。
你不能这样做
If you call Show(String) method from the app Activated and Launching event handlers an InvalidOperationException is thrown with the message Error Displaying MessageBox.
它在msdn
如果你想显示相同的消息我的建议是使用OnNavigatedTo
事件
编辑
如果我理解正确你想改变默认页面导航
-
1.一种方法:
在
WMAppManifest.xml
将Navigation Page
的属性替换为您想要的页面 -
替代:
在WMAppManifest.xml
删除Navigation Page
的属性
private void Application_Launching(object sender, LaunchingEventArgs e) { RootFrame.Navigate(new Uri("YourPage.xaml", UriKind.Relative)); }
private void Application_Activated(object sender, ActivatedEventArgs e) { RootFrame.Navigate(new Uri("YourPage.xaml", UriKind.Relative)); }
这样,您可以使用IsolatedStorageSettings
“播放”
if (boolvariable) { RootFrame.Navigate(new Uri("YourPage.xaml", UriKind.Relative)); boolvariable = false; } else { RootFrame.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); }
这只是一个想法,让我知道它是怎么回事(: