title: Intercepting the Mouse back button in a Xamarin.Forms UWP App
body: <p>I've been trying to intercept the user going back from a page in my Xamarin.Forms UWP app, in order to either block it or present them with an "Are you sure?" dialog.</p>
  
  <p>I've been able to remove the navigation bar back button using this in the constructor of the ContentPage:</p>
  
  <pre><code>NavigationPage.SetHasBackButton(this, false);
  </code></pre>
  
  <p>However, the back button on the mouse (XButton1) still causes the page to back.
  I tried disabling it using this on the page:</p>
  
  <pre><code>protected override bool OnBackButtonPressed()
  {
      return true;
  }
  </code></pre>
  
  <p>This would disable the hardware back button on something like Android, but it is not called at all when hitting the mouse back button.
  I've also tried playing with the PointerPressed event on the UWP MainPage:</p>
  
  <pre><code>public MainPage()
  {
      this.InitializeComponent();
  
      LoadApplication(new MyApp.App());
  
      this.PointerPressed += MainPage_PointerPressed;
  }
  
  private void MainPage_PointerPressed(object sender, PointerRoutedEventArgs e)
  {
      PointerPoint currentPoint = e.GetCurrentPoint(this);
      if (currentPoint.PointerDevice.PointerDeviceType == PointerDeviceType.Mouse)
      {
          PointerPointProperties pointerProperties = currentPoint.Properties;
  
          if (pointerProperties.IsXButton1Pressed)
          {
              // back button pressed
          }
      }
  }
  </code></pre>
  
  <p>This method is called correctly for all mouse inputs <em>except</em> for the XButton1 mouse back button <em>if</em> the app's current page is currently in a NavigationPage - almost like Xamarin.Forms is intercepting it somewhere along the way. Outside of a navigation page it picks up the XButton1 fine, and it always picks up every other input (including XButton2).</p>
  
  <p>Is there a way to intercept or disable the XButton1 back function for a Xamarin.Forms UWP app?</p>