Windows phone 7 导航到WMAppManifest.xml中设置的Deafult页面以外的页面

Windows phone 7 导航到WMAppManifest.xml中设置的Deafult页面以外的页面,windows-phone-7,windows-phone-8,windows-phone,Windows Phone 7,Windows Phone 8,Windows Phone,众所周知,我们必须在WMAppManifest文件中定义默认导航页面。默认情况下,我使用了MainPage.xaml页面,但我想在应用程序启动时导航到其他页面。我不想从WMAppManifest文件中删除MainPage 目前,我已经尝试了以下的事情 在加载的主页上,我导航到第二页 在App.xaml.cs中,我在CompleteInitializePhoneApplication方法中设置了以下代码 RootFrame.Source = new Uri("/Songslist.xaml",

众所周知,我们必须在
WMAppManifest
文件中定义默认导航页面。默认情况下,我使用了
MainPage.xaml
页面,但我想在应用程序启动时导航到其他页面。我不想从WMAppManifest文件中删除MainPage

目前,我已经尝试了以下的事情

  • 在加载的主页上,我导航到第二页
  • 在App.xaml.cs中,我在
    CompleteInitializePhoneApplication
    方法中设置了以下代码

    RootFrame.Source = new Uri("/Songslist.xaml", UriKind.RelativeOrAbsolute);
    
两者都在工作,但应用程序在导航过程中会挂起几秒钟,这会让人看起来很糟糕。我无法上传sceenshot,因为它会持续几秒钟。我怎样才能做到这一点? 当我处理以下代码时,我得到了NullReference异常,因为RootVisual=null

    (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/Songslist.xaml", UriKind.RelativeOrAbsolute));

您应该使用
UriMapper
,它将允许您根据条件将应用重定向到特定页面。下面是如何做到的:

在App.xaml.cs中应用程序构造函数的末尾,将
RootFrame.UriMapper
设置为一个新的
UriMapper
,以执行重定向:

var mapper = new UriMapper();
string page = "/Songslist.xaml";

// Here you map "MainPage.xaml" to "Songslist.xaml"
mapper.UriMappings.Add(new UriMapping
{
    Uri = new Uri("/MainPage.xaml", UriKind.Relative),
    MappedUri = new Uri(page, UriKind.Relative)
});

this.RootFrame.UriMapper = mapper;

优点是它不应该再挂起,并且在后堆栈中不会有
MainPage.xaml

您应该给我们一个
UriMapper
,它将允许您根据条件将应用重定向到特定页面。下面是如何做到的:

在App.xaml.cs中应用程序构造函数的末尾,将
RootFrame.UriMapper
设置为一个新的
UriMapper
,以执行重定向:

var mapper = new UriMapper();
string page = "/Songslist.xaml";

// Here you map "MainPage.xaml" to "Songslist.xaml"
mapper.UriMappings.Add(new UriMapping
{
    Uri = new Uri("/MainPage.xaml", UriKind.Relative),
    MappedUri = new Uri(page, UriKind.Relative)
});

this.RootFrame.UriMapper = mapper;

优点是它不应该再挂了,在后堆栈中不会有
MainPage.xaml

你可以在昨天提出的这个问题中找到三种不同的解决方案:你可以在昨天提出的这个问题中找到三种不同的解决方案:你需要将App.xaml.cs文件放在应用程序构造函数的末尾,以提高其工作效率,但如果我是导航到主页,它再次将我重定向到歌曲列表页。发生了什么事?好的,我正在将Songslist构造函数上的urimapper重置为null。现在可以工作了。这很正常,UriMapper指示每次你尝试转到Page1.xaml时,它都应该转到Page2.xaml。你需要将它放在应用程序构造函数末尾的App.xaml.cs文件中,以提高它的工作效率,但如果我导航到主页,它会再次将我重定向到songslist页面。发生了什么事?好的,我正在将Songslist构造函数上的urimapper重置为null。现在可以工作了。这很正常,UriMapper指示每次尝试转到Page1.xaml时,它都应该转到Page2.xaml。