2

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)
    'we halen de virtuele waarde van de ingedrukte knop op
    Dim Value As String = e.VirtualKey

    'Enter knop
    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 don't know why.

Romasz
  • 29,662
  • 13
  • 79
  • 154
A.Pols
  • 21
  • 3
  • What do you mean by 'it stops'? Does it crash, hang, throw exception? Have you tried the same code on desktop? – Romasz Apr 05 '17 at 16:45
  • The enter button dit not work anymore but i found the solution, in every page i had to remove the handler. Protected Overrides Sub OnNavigatingFrom(e As NavigatingCancelEventArgs) RemoveHandler Window.Current.CoreWindow.KeyUp, AddressOf CoreWindow_KeyUp End Sub – A.Pols Apr 05 '17 at 18:52
  • It may be better to remove the handler inside itself, just before `GotoNext()` RemoveHandler. On IoT it won't probably make a difference, but note that NavigatedFrom can be also invoked from other reasons than user's click. – Romasz Apr 05 '17 at 18:58
  • Thank you it works now!! – A.Pols Apr 07 '17 at 12:17

0 Answers0