目前,我的应用程序在启动时转到 MainPage.xaml
(虽然我不知道它在哪里配置)。
我希望在某些情况下能够从另一个页面开始。我想我可以将此代码添加到 App.xaml.cs
页面中的 Application_Launching()
:
NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative));
但是 NavigationService
在 App.xaml.cs 中不可用。
如果 foo == true
,我如何使用另一个页面启动应用程序?
最佳答案
更改 App.Xaml.cs
中的起始页:
private void Application_Launching(object sender, LaunchingEventArgs e)
{
Uri nUri = new Uri("/SecondPage.xaml", UriKind.Relative);
((App)Application.Current).RootFrame.Navigate(nUri);
}
在Property\WMAppManifest.xml
文件中设置静态启动页
<DefaultTask Name ="_default" NavigationPage="SecondPage.xaml"/>
编辑
试一试:
private void Application_Launching(object sender, LaunchingEventArgs e)
{
Uri nUri = new Uri("/GamePage.xaml", UriKind.Relative);
RootFrame.Navigate(nUri);
}
并在 Property\WMAppManifest.xml
中清除 NavigationPage:
<DefaultTask Name ="_default" NavigationPage=""/>
关于c# - 如何在启动时更改起始页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19169657/