提问人:Ahmed.C 提问时间:11/18/2013 更新时间:11/20/2013 访问量:94
WP7 页面导航..Null 异常
WP7 Page Navigation..Null exception
问:
我正在制作该应用程序,它涉及使用文本文件等编写本地帐户。首次运行时,该应用程序旨在导航到名为“MainPage”的页面,但是,如果该文件“FTR.dat”不存在于此特定文件夹中,则它将导航到“CreateAccount”页面,但如果文件“FTR.dat”确实存在于该特定文件夹中,则它将导航到“MainPage”
但是我收到这个nullrefrenceexception错误: 这是我的代码:
Dim myIsolatedStorage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
If myIsolatedStorage.FileExists("PasswordManagerAccount/FTR.dat") = False Then
NavigationService.Navigate(New Uri("/CreateAccount.xaml", UriKind.Relative))
ElseIf myIsolatedStorage.FileExists("PasswordManagerAccount/FTR.dat") = True Then
NavigationService.Navigate(New Uri("/MainPage.xaml", UriKind.Relative))
End If
谢谢!
答:
1赞
Kevin Gosse
11/20/2013
#1
不能从页面构造函数调用此类代码,因为导航服务尚未初始化。将其移至活动或:Loaded
OnNavigatedTo
Protected Overrides Sub OnNavigatedTo(ByVal e As System.Windows.Navigation.NavigationEventArgs)
Dim myIsolatedStorage As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication()
If myIsolatedStorage.FileExists("PasswordManagerAccount/FTR.dat") = False Then
NavigationService.Navigate(New Uri("/CreateAccount.xaml", UriKind.Relative))
ElseIf myIsolatedStorage.FileExists("PasswordManagerAccount/FTR.dat") = True Then
NavigationService.Navigate(New Uri("/MainPage.xaml", UriKind.Relative))
End If
End Sub
评论