title: How to handle the back button on WP 8.1 using MVVM light?
body: <p>I'm searching for the appropiate way to handle the back button pressed event on Windows Phone 8.1 WinRT using the <code>NavigationService</code> available on MVVM light 5.</p>
  
  <p>So far I think the best place to do it is inside the <code>ViewModelLocator</code> by registering the <code>GoBack</code> method of the <code>NavigationService</code> while creating it following the approach outlined in <a href="https://marcominerva.wordpress.com/2014/10/10/navigationservice-in-mvvm-light-v5/" rel="nofollow">NavigationService in MVVM Light V5</a></p>
  
  <p>This is an effective approach. However, I can't handle validation before navigating back so I was wondering if there is a more suitable way to handle this event.</p>
  
  <pre><code>public class ViewModelLocator
  {
      public ViewModelLocator()
      {
          ServiceLocator.SetLocatorProvider(() =&gt; SimpleIoc.Default);
          // Register NavigationService
          SimpleIoc.Default.Register(CreateNavigationService);
          // Register ViewModels here
      }
  
      private INavigationService CreateNavigationService()
      {
          var navigationService = new NavigationService();
          // Register pages here
          navigationService.Configure("Details", typeof(DetailsPage));
          // Handle back button
          HardwareButtons.BackPressed += (sender, args) =&gt; {
              navigationService.GoBack();
              args.Handled = true;
          }; 
          return navigationService;
      }
  }
  </code></pre>