WindowsPhone设置启动欢迎页面
在建立 Windows Phone 专案时,都会建立一个预设启动的页面 -- MainPage.xaml。但有的时候会希望能在 app 启动时,根据一些逻辑判断而选择不同的页面来启动,这时可以采用以下的作法。
首先,以查看代码形式将目录中的 Properties\WMAppManifest.xml 的 <Tasks></Tasks> 标签中的<DefaultTask> 修改为
<Tasks>
<DefaultTask Name="_default" />
</Tasks>
<DefaultTask Name="_default" />
</Tasks>
將原本設定的 NavigationPage="MainPage.xaml" 拿掉。
這樣的修改完畢後,再到 App.xaml.cs 檔案中,在 Application_Launching 事件中就可以自己決定要載入的画面(Page1.xaml 或 Page2.xaml),代码如下:
private void Application_Launching(object sender, LaunchingEventArgs e)
{
string target;
if (判斷式1)
{
target = "Page1.xaml";
}
else
{
target = "Page2.xaml";
}
RootFrame.Navigate(new Uri(target, UriKind.Relative));
}
浙公网安备 33010602011771号