微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

windows-phone-7 – 如何在WP7应用程序上更改启动页面

我希望有不同的起始页面,具体取决于是否存在IsolatedStorage中存储的某些设置.

我不知道处理这个问题的最佳做法在哪里.即如果我在隔离存储中找到某些内容,我会让用户获取MainPage,否则我会像用户一样获取设置页面.

如果有一些神奇的东西可以用,我正在使用MVVM-light.

BR

您可以通过将虚拟页面设置为项目的主页面来完成此操作.您可以通过编辑项目的WMAppManifest.xml文件来更改主页面
<DefaultTask Name="_default" NavigationPage="DummyPage.xaml" />

现在,检测指向虚拟页面的所有导航,并重定向到您想要的任何页面.

为此,在App.xaml.cs文件中,在构造函数的末尾,订阅“导航”事件:

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)));
    }
}

编辑

实际上,更容易.在app构造函数的最后,只需使用您想要的替换Uri设置UriMapper:

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;

原文地址:https://www.jb51.cc/windows/363535.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐