我希望根据存储在独立存储中的设置,拥有不同的起始页面。
但我不知道如何处理最佳实践。例如,如果我在独立存储中找到一些内容,我希望用户获得主页;否则,我希望用户获得设置页面。
如果有神奇的方法可以使用,我正在使用MVVM-light。
敬礼
我希望根据存储在独立存储中的设置,拥有不同的起始页面。
但我不知道如何处理最佳实践。例如,如果我在独立存储中找到一些内容,我希望用户获得主页;否则,我希望用户获得设置页面。
如果有神奇的方法可以使用,我正在使用MVVM-light。
敬礼
<DefaultTask Name="_default" NavigationPage="DummyPage.xaml" />
this.RootFrame.Navigating += this.RootFrame_Navigating;
void RootFrame_Navigating(object sender, NavigatingCancelEventArgs e)
{
if (e.Uri.OriginalString == "/DummyPage.xaml")
{
e.Cancel = true;
var navigationService = (NavigationService)sender;
// Insert here your logic to load the destination page from the isolated storage
string destinationPage = "/Page2.xaml";
this.RootFrame.Dispatcher.BeginInvoke(() => navigationService.Navigate(new Uri(destinationPage, UriKind.Relative)));
}
}
编辑
实际上,有一种更简单的方法。在应用程序构造函数的末尾,只需设置一个UriMapper和您想要替换的Uri:
var mapper = new UriMapper();
mapper.UriMappings.Add(new UriMapping
{
Uri = new Uri("/DummyPage.xaml", UriKind.Relative),
MappedUri = new Uri("/Page2.xaml", UriKind.Relative)
});
this.RootFrame.UriMapper = mapper;