Harvey Harvey - 2 months ago 12
Vb.net Question

Universal Windows 10 App. How to use Back Button? VB.NET

In my application the app closes if the back button is pressed on a child page.

How can I called Frame.Navigate on a back button press?

I have seen examples how to do this in C# but these do not seem to translate over too well into VB.NET.

Below is a method of which I have tried

Private Sub OnHardwareButtonsBackPressed(sender As Object, e As Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested)
Frame.GoBack()
End Sub


This throws a hicup at declaring the type of event.

Also trying to handle the event
Windows.UI.Core.SystemNaviationManager
although this had no success in intercepting the back button.

Answer

The correct syntax is:

Private Sub OnHardwareButtonsBackPressed(sender As Object, e As BackRequestedEventArgs)
    ' Tell the app that you have handled the event
    ' Otherwise, the back button will be processed normally and the app will close
    e.handled = true
End Sub

Then, to attach your event:

AddHandler SystemNavigationManager.GetForCurrentView().BackRequested, AddressOf OnHardwareButtonsBackPressed