Windows phone 7 WP7页面导航..空异常

Windows phone 7 WP7页面导航..空异常,windows-phone-7,navigation,nullreferenceexception,Windows Phone 7,Navigation,Nullreferenceexception,我正在制作这个应用程序,它涉及到使用文本文件等创建一个本地帐户。在第一次运行时,该应用程序旨在导航到名为“MainPage”的页面,但是,如果文件“FTR.dat”不存在于这个特定的文件夹中,那么它将导航到“CreateCount”页面,但是如果文件“FTR.dat”确实存在于某个文件夹中,然后它将导航到“主页” 但我得到了一个NullReferenceException错误: 这是我的密码: Dim myIsolatedStorage As IsolatedStorageFile = Is

我正在制作这个应用程序,它涉及到使用文本文件等创建一个本地帐户。在第一次运行时,该应用程序旨在导航到名为“MainPage”的页面,但是,如果文件“FTR.dat”不存在于这个特定的文件夹中,那么它将导航到“CreateCount”页面,但是如果文件“FTR.dat”确实存在于某个文件夹中,然后它将导航到“主页”

但我得到了一个NullReferenceException错误: 这是我的密码:

  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

谢谢

您无法从页面构造函数调用此类代码,因为导航服务尚未初始化。将其移动到已加载的
事件或已导航到的
事件:

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

让我猜猜:你是从页面的构造器调用此代码嗨,我很抱歉回复太晚!但是是的,如果你是这个意思的话,我是在主页上说的。那么我如何执行这个呢?