NavigationService.Navigate抛出NullReferenceException WP7?

时间:2012-04-13 08:49:50

标签: windows-phone-7 nullreferenceexception

刚刚下载了WP7 SDK - 我是Silver Light的新手 - 以及一般的应用程序开发。

我只是简单地尝试将用户定向到另一个页面,但是我在代码行上发生了NullRefernceException错误。 愚蠢的事情 - 它上面的代码是完全一样的 - 但不会抛出错误?

if (myISO.DirectoryExists("Logs") && myISO.DirectoryExists("DataStore"))
{
     NavigationService.Navigate(new Uri("Sign-in.xaml", UriKind.Relative));
}
else
{
     NavigationService.Navigate(new Uri("Welcome.xaml", UriKind.Relative));
     //Above Line Causes Exception^
}

此外,我在App.xaml.cs中得到一个NullRefernceException - 我甚至没有改变 - 它正在工作 - 现在它没有:

PhoneApplicationService.Current.UserIdleDetectionMode = IdleDetectionMode.Disabled;

3 个答案:

答案 0 :(得分:1)

应该是这样的

NavigationService.Navigate(new Uri("/Page1.xaml", UriKind.Relative));

你的“/”

在哪里?

答案 1 :(得分:0)

您可以调试并识别行的哪一部分引发异常吗?

此外,如果您使用NavigationService.Navigate(new Uri(“/ Welcome.xaml”,UriKind.Relative));使用“/”确保Welcome.xaml页面位于项目的根目录中。

答案 2 :(得分:0)

实际上,

This problem occurs after you change the Assembly Name or Namespace in 
Project Properties.

要修复它,请删除Bin和obj文件夹的所有内容并重新编译。见thread

这也许是你创建新项目时它起作用的原因。

相关问题