I'm making the app and it involves crating a local account using textfiles etc. At first time run, the app is meant to navigate to the page called "MainPage" but, if the file "FTR.dat" doesn't exist in this certain folder then it will navigate to "CreateAccount" page but if the file "FTR.dat" does exist in that certain folder then it wil navigate to "MainPage"
but I get this nullrefrenceexception error: Here's my code:
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
Thanks!
You can't call this kind of code from the page constructor because the navigation service hasn't been initialized yet. Move it to the Loaded
event or 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.