0

I am creating a Windows universal app and I would like to implement some behavior for the (hardware)back button. I am able to do so for windows Phone using 'using Windows.Phone.UI.Input;' and 'HardwareButtons.BackPressed += HardwareButtons_BackPressed;'

But can't seem to do it with the universal app, This behavior will happen on a page that is shared. How can I do this?

Calin956
  • 25
  • 1
  • 7
  • 1
    Have a look at this link http://stackoverflow.com/questions/31832309/handling-back-navigationn-windows-10-uwp – Shahriar Nov 14 '15 at 20:20
  • yes, i can't use 'Windows.Phone'... that can only be used on the phone part of the universal app, and i want to get the press event on a shared page(for both windows and windowsPhone)... – Calin956 Nov 14 '15 at 20:29
  • 2
    `SystemNavigationManager` is what you want. It also works on desktop. – Raymond Chen Nov 14 '15 at 20:50

1 Answers1

1

You can use SystemNavigationManager

SystemNavigationManager currentView = SystemNavigationManager.GetForCurrentView();

And have an event handler like this one:

currentView.BackRequested += CurrentView_BackRequested;

private void CurrentView_BackRequested(object sender,BackRequestedEventArgs e) {
    e.Handled = true;
    if(Frame.CanGoBack)
      try { Frame.GoBack(); }
      catch(Exception) { }
}

And to Visible Back Button at corner of ur app (Desktop mode) :

currentView.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
Shahriar
  • 939
  • 1
  • 14
  • 36