locked
Page navigation problem RRS feed

  • Question

  • Hello,

    Im from holland so sorry for my bad english,

    I'm builing an app for windows iot core on a raspberry pi 3. it is a scoreboard fot playing billiard. The app has to work with a numpad only.

    The problem is, i want to navigate between pages when the user presses the enter key, but after a couple of times de enter key doesn't work anymore.

    I have made a simple code to let you see what i mean.

    mainpage and onother two pages. This is the testcode.

    The mainpage

    Imports Windows.UI.Core
    
    Public NotInheritable Class MainPage
    Inherits Page
    
    Public Sub New()
        Me.InitializeComponent()
    
        AddHandler Window.Current.CoreWindow.KeyUp, AddressOf CoreWindow_KeyUp
    End Sub
    
    Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
    
    End Sub
    
    
    Private Sub CoreWindow_KeyUp(sender As CoreWindow, e As KeyEventArgs)
    
        Dim Value As String = e.VirtualKey
    
        'Enter
        If Value = "13" Then
            GotoNext()
        End If
    
    End Sub
    
    Private Sub GotoNext()
        Frame.Navigate(GetType(BlankPage1))
    End Sub
    
    End Class

    Page 1

    Imports Windows.UI.Core
    
    Public NotInheritable Class BlankPage1
    Inherits Page
    
    Public Sub New()
        Me.InitializeComponent()
    
        AddHandler Window.Current.CoreWindow.KeyUp, AddressOf CoreWindow_KeyUp
    End Sub
    
    Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
    
    End Sub
    
    
    Private Sub CoreWindow_KeyUp(sender As CoreWindow, e As KeyEventArgs)
        Dim Value As String = e.VirtualKey
    
        'Enter button
        If Value = "13" Then
            GotoNext()
        End If
    
    End Sub
    
    Private Sub GotoNext()
        Frame.Navigate(GetType(Blankpage2))
    End Sub
    
    End Class

    Page 2

    Imports Windows.UI.Core
    
    Public NotInheritable Class BlankPage2
    Inherits Page
    
    Public Sub New()
        Me.InitializeComponent()
    
        AddHandler Window.Current.CoreWindow.KeyUp, AddressOf CoreWindow_KeyUp
    End Sub
    
    Protected Overrides Sub OnNavigatedTo(e As NavigationEventArgs)
    
    End Sub
    
    
    Private Sub CoreWindow_KeyUp(sender As CoreWindow, e As KeyEventArgs)
    
        Dim Value As String = e.VirtualKey
    
        If Value = "13" Then
            GotoNext()
        End If
    
    End Sub
    
    Private Sub GotoNext()
        Frame.Navigate(GetType(MainPage))
    End Sub
    
    End Class

    Strangely when you hit enter 9 times it stops and i do'n know why!!

    Can you please help me?

    Adrie Pols

    Wednesday, April 5, 2017 4:42 PM

Answers

  • Hello A.Pols

    Look what you do. On each page constructor you subscribe on CoreWindow.KeyUp event and on Page1 you already have two event Handlers for the same event and both will be invoked, on Page3 you have three handlers. You should in each page  OnNavigatingFrom callback unsubscribe from the event.


    Make the community better together

    • Proposed as answer by Breeze Liu Thursday, April 20, 2017 2:14 AM
    • Marked as answer by A.Pols Thursday, May 18, 2017 1:00 PM
    Wednesday, April 5, 2017 5:01 PM

All replies

  • Hello A.Pols

    Look what you do. On each page constructor you subscribe on CoreWindow.KeyUp event and on Page1 you already have two event Handlers for the same event and both will be invoked, on Page3 you have three handlers. You should in each page  OnNavigatingFrom callback unsubscribe from the event.


    Make the community better together

    • Proposed as answer by Breeze Liu Thursday, April 20, 2017 2:14 AM
    • Marked as answer by A.Pols Thursday, May 18, 2017 1:00 PM
    Wednesday, April 5, 2017 5:01 PM
  • Hello thank you for the fast reply, But can you maby explain a little bit more please?


    • Edited by A.Pols Wednesday, April 5, 2017 5:16 PM
    Wednesday, April 5, 2017 5:15 PM
  • Sorry for the trouble it worked as you say, for the people who want to know, i did this on every page

    Thank you so much Azat Tazayan

        Protected Overrides Sub OnNavigatingFrom(e As NavigatingCancelEventArgs)
            RemoveHandler Window.Current.CoreWindow.KeyUp, AddressOf CoreWindow_KeyUp
        End Sub

    Wednesday, April 5, 2017 6:29 PM
  • If some answers on this forum help you to solve your problem don't forgot mark it as answer. Thanks 

    Make the community better together

    Thursday, April 6, 2017 5:13 AM