0

昨天刚刚下载了 WP7 SDK - 我是 Silver light 的新手 - 和一般的应用程序开发。

我只是试图将我的用户定向到不同的页面,但我在一行代码上发生了 NullReferenceException 错误。愚蠢的事情-上面的代码完全相同-但不会抛出错误?

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;
4

3 回答 3

1

应该是这样的

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

你的“/”在哪里?

于 2012-04-13T08:56:52.387 回答
0

您可以调试并确定行的哪一部分引发了异常吗?

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

于 2012-04-13T13:26:54.073 回答
0

实际上,

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

要修复它,请删除 Bin 和 obj 文件夹的所有内容并重新编译。看到这个线程

这也可能是您创建新项目时它起作用的原因。

于 2012-05-22T14:09:09.277 回答