问题描述
我需要在我的应用程序第一次运行时导航到某个页面,以收集登录详细信息等.我正在使用 IsloatedStorageSettings 保存一个值以确定这是否是应用程序的第一次运行,这很有效很好.
I need to navigate to a certain page the first time my app is run, to gather login details etc. I'm using IsloatedStorageSettings to save a value to determine if this is the first run of the app or not, which works fine.
我的问题实际上是在第一次运行应用程序时导航到我的首次运行"页面,使用 NavigationService,此时 NavigationService 似乎尚未创建,因此仍然为空.NavigationService 何时创建或者我该如何解决这个问题?
My problem is actually navigating to my 'first run' page when the app is run for the first time, using NavigationService, it seems NavigationService is not created at this point so is still null. When is NavigationService created or how can I work around this?
我的代码(在我的主页的构造函数中:
My code (in the constructor of my main page:
if ((bool)settings["firstRun"])
{
if (NavigationService != null)
{
NavigationService.Navigate(new Uri("/FirstRun.xaml", UriKind.Relative));
}
else
{
MessageBox.Show("Navigation service must be null?"); //always prompts
}
}
else
{
InitializeComponent();
}
推荐答案
Peter Torr 有一个很棒的 博客文章 关于初始导航重定向的来龙去脉,但对于用户登录,我建议您要么使用全屏弹出窗口,要么在正常"开始页面上有一个登录控件,并根据您的第一次运行条件切换可见性.
Peter Torr has a great blog post on the ins and outs of redirecting for the initial navigation, though for user login I'd suggest that you either use a full screen popup or have a login control on your "normal" start page and toggle visibility based on your first run condition.
这篇关于WP7 导航 - NullReferenceException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!