use*_*173 5 c# windows-phone-8
我有一个应用程序,当RootFrame首次初始化时,我会检查它是否是第一次启动应用程序.如果是,则将RootFrame UriMapper更改为教程页面.问题是,我似乎无法想出一种方法将用户重定向回MainPage.xaml.到目前为止它不会做任何事情.
这是我用于更改App构造函数中的初始启动页面的代码:
if (App.Model.SelectFirstStart())
{
var mapper = new UriMapper();
mapper.UriMappings.Add(new UriMapping
{
Uri = new Uri("/MainPage.xaml", UriKind.Relative),
MappedUri = new Uri("/TutorialPage.xaml", UriKind.Relative)
});
RootFrame.UriMapper = mapper;
}
Run Code Online (Sandbox Code Playgroud)
当用户点击教程页面中的按钮时,它应该将它们重定向到MainPage.xaml.这是我到目前为止所尝试的:
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
Run Code Online (Sandbox Code Playgroud)
和:
App.RootFrame.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
Run Code Online (Sandbox Code Playgroud)
任何帮助将非常感激.谢谢
我看到了几个问题.
首先,您没有更改教程页面中的映射,因此基本上MainPage.xaml仍然映射到TutorialPage.xaml.
第二个问题是即使在修复之后,导航MainPage.xaml仍然无法工作,因为尽管实际的页面存在TutorialPage.xaml,RootFrame.CurrentSource仍将指向MainPage.xaml无论如何.
要解决此问题,您需要在教程页面的按钮单击中执行以下操作
// Inside the Button click event of TutorialPage.xaml
// Change the mapping so that MainPage points to itself
((UriMapper)App.RootFrame.UriMapper).UriMappings[0].MappedUri =
new Uri("/MainPage.xaml", UriKind.Relative);
// Since RootFrame.CurrentSource is still set to MainPage, you need to pass
// some dummy query string to force the navigation
App.RootFrame.Navigate(new Uri("/MainPage.xaml?dummy=1", UriKind.Relative));
// Remove back entry so that if user taps the back button
// you won't get back to tutorial
App.RootFrame.RemoveBackEntry();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1805 次 |
| 最近记录: |