Frage

So I took a break and went from C# to VB in developing Windows Phone 8 apps. It's just more of a test and I have this really strange problem.

First off all my basic scenario is that I have Page A and Page B. The user has to fill in a few details before going to Page B. Page B will only be shown if the user has already filled out the information in Page A, sort of like a first time run.

What I've done is that I've added this code:

Private Sub createbtn_Click(sender As Object, e As RoutedEventArgs) Handles createbtn.Click
    '...
    IsoSettings.Add("AccountCreated", Nothing)
    NavigationService.Navigate(New Uri("/MainMenu.xaml", UriKind.Relative))
    NavigationService.RemoveBackEntry()
End Sub

Once the user clicks on the "create account" button. He will be navigated to Page B and hereafter the user will not have to go through filling out the information in Page A. The "AccountCreated" is a sort of Check. In here:

Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)        
    If IsoSettings.Contains("AccountCreated") Then            
        NavigationService.Navigate(New Uri("/MainMenu.xaml", UriKind.Relative)) 'Page B
        NavigationService.RemoveBackEntry()          
    Else
        NavigationService.Navigate(New Uri("/MainPage.xaml", UriKind.Relative)) 'Page A
    End If
End Sub

So basically that checks and sees if IsoSettings contains "AccountCreated" then take the user to Page B, if not take him to Page A. Now this way works fine. No problems. Works the way I want it to.

Now I've added a settings page. There is one setting where the user can decide whether to show the Login page or not. If it's "off" then obviously it's not going to be shown and On...

I've added this:

If IsoSettings.Contains("AccountCreated") Then
        Try
            Dim ShowLoginPage As Byte = CByte(AppSettings("StartupLogin"))
            If ShowLoginPage = 0 Then
                NavigationService.Navigate(New Uri("/LoginPage.xaml", UriKind.Relative))
                NavigationService.RemoveBackEntry()
            ElseIf ShowLoginPage = 1 Then
                NavigationService.Navigate(New Uri("/MainMenu.xaml", UriKind.Relative))
                NavigationService.RemoveBackEntry()
            End If
        Catch ex As KeyNotFoundException
            AppSettings.Add("StartupLogin", 0)
        End Try
    Else
        NavigationService.Navigate(New Uri("/MainPage.xaml", UriKind.Relative))
End If

Now this is where the problem occurs. So when the user first runs this app. He has to go through Page A. He fills the information and then get's navigated to the Login page. Now once the user logs in or just closes the app while in the login page and re-opens it, the users gets navigated to Page A, to fix this the user has to close the app and re-open it.

Can someone please clear things for me? Thanks!

War es hilfreich?

Lösung

I'm not sure if I had understood correctly and what is in the rest of the code, but from provided one it turns out for me that:

  • the first time your App runs. the line Dim ShowLoginPage As Byte = CByte(AppSettings("StartupLogin")) throws the exceptions - there is no StartupLigin in AppSettings, so it is adding it but Navigation follows as exception is handeled.
  • for the second time StartupLigin exists so it goes thru the if statements

I think it will be suitable if you had checked for the first run in Application_Launching() in App.xaml.cs.

I also don't see where you save your AppSettings - if you want your data to be preserved you should do it.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top