问题描述
限时送ChatGPT账号..我有一个应用程序,当 RootFrame 首次初始化时,我让它检查该应用程序是否是第一次启动.如果是,它会将 RootFrame UriMapper 更改为教程页面.问题是,我似乎无法找到将用户重定向回 MainPage.xaml 的方法.到目前为止它不会做任何事情.
I have an app, and when the RootFrame is first initialized, I have it checking if its the first time the app has been launched. If it is, it changes the RootFrame UriMapper to a tutorial page. the problem is, I can't seem to figure out a way to redirect the user back to MainPage.xaml. It just won't do anything so far.
这是我用于更改 App 构造函数中初始启动页面的代码:
This is the code I'm using for changing the initial start up page in the App constructor:
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;
}
当用户点击教程页面中的按钮时,它应该将它们重定向到 MainPage.xaml.这是我迄今为止尝试过的:
When the user taps a button in the tutorial page, it should redirect them to the MainPage.xaml. This is what I've tried so far:
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
还有:
App.RootFrame.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
任何帮助将不胜感激.谢谢
Any help would be much appreciated. Thank you
推荐答案
我看到了几个问题.
首先,您没有更改教程页面中的映射,因此基本上 MainPage.xaml
仍然映射到 TutorialPage.xaml
.
First, you are not changing the mapping in your tutorial page so basically MainPage.xaml
still maps to TutorialPage.xaml
.
第二个问题是即使在修复之后,导航到 MainPage.xaml
仍然无法工作,因为尽管实际页面是 TutorialPage.xaml
, RootFrame.CurrentSource
仍然会指向 MainPage.xaml
.
Second issue is even after fixing that, navigation to MainPage.xaml
will still not work because despite the actual page being TutorialPage.xaml
, RootFrame.CurrentSource
will still point to MainPage.xaml
no matter what.
要解决此问题,您需要在教程页面的按钮单击中执行以下操作
To fix this you need to do the following in your tutorial page's button click
// 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();
这篇关于在 Windows Phone 8 中更改 UriMapper 后重定向页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论