title: UWP MVVM NavigationView BackButton - Detect when it is pressed
body: <p>This question is in the context of using MVVM pattern. I have a NavigationView in my XAML but I have no way to detect when the user clicks on the back button. I could do it in the code behind file easily but that doesnt seems like what you want to do in an MVVM context. So is there a way to detect when the user presses the back button from a NavigationView outside of the code behind cs file? I would attach a Command Object to it and use my NavigationService where I will be able to switch the Frame. So far I use the Behaviors NuGet package to detect the clicks on the MenuItems but it doesnt work for the BackButton. Here is the Xaml so far:</p>
  <pre><code>&lt;Page
      x:Class=&quot;ToolBoxApp.Views.AudioHomeView&quot;
      xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
      xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
      xmlns:local=&quot;using:ToolBoxApp.Views&quot;
      xmlns:viewmodels=&quot;using:ToolBoxApp.ViewModels&quot;
      xmlns:mainview=&quot;clr-namespace:ToolBoxApp&quot;
      xmlns:d=&quot;http://schemas.microsoft.com/expression/blend/2008&quot;
      xmlns:mc=&quot;http://schemas.openxmlformats.org/markup-compatibility/2006&quot;
      xmlns:i=&quot;using:Microsoft.Xaml.Interactivity&quot;
      xmlns:core=&quot;using:Microsoft.Xaml.Interactions.Core&quot;
      mc:Ignorable=&quot;d&quot;
      Background=&quot;{ThemeResource ApplicationPageBackgroundThemeBrush}&quot;&gt;
      
      &lt;Grid&gt;
          &lt;NavigationView x:Name=&quot;navigationViewControl&quot; 
                          IsBackEnabled=&quot;true&quot;&gt;
  
              &lt;i:Interaction.Behaviors&gt;
                  &lt;core:EventTriggerBehavior EventName=&quot;ItemInvoked&quot;&gt;
                      &lt;core:EventTriggerBehavior.Actions&gt;
                          &lt;core:InvokeCommandAction Command=&quot;{Binding NavigateToView}&quot; /&gt;
                      &lt;/core:EventTriggerBehavior.Actions&gt;
                  &lt;/core:EventTriggerBehavior&gt;
              &lt;/i:Interaction.Behaviors&gt;
  
              &lt;NavigationView.MenuItems&gt;
                  &lt;NavigationViewItem Icon=&quot;MusicInfo&quot; Content=&quot;Text to Speech&quot;/&gt;
                  &lt;NavigationViewItem Icon=&quot;MusicInfo&quot; Content=&quot;Youtube to Mp3&quot;/&gt;
              &lt;/NavigationView.MenuItems&gt;
  
              &lt;ScrollViewer&gt;
                  &lt;Frame SourcePageType=&quot;{Binding ScrollAudioView, Mode=TwoWay}&quot;/&gt;
              &lt;/ScrollViewer&gt;
  
          &lt;/NavigationView&gt;
      &lt;/Grid&gt;
  &lt;/Page&gt;
  </code></pre>