title: UWP Back Button and Event Handler - C++
body: <p>I am new to Windows 10 UWP apps and currently I am trying out various navigation techniques in apps. I have searched for the back button functionality in UWP apps but cant seem to understand that where do I have to put the "provided code" and how to execute it. I have also tried to do it on my own but it throws various errors in Visual Studio about identifier not found.</p>
  
  <p>The first code is:</p>
  
  <pre><code>    Windows::UI::Core::SystemNavigationManager::GetForCurrentView()-&gt;
      BackRequested += ref new Windows::Foundation::EventHandler&lt;
      Windows::UI::Core::BackRequestedEventArgs^&gt;(
      this, &amp;App::App_BackRequested);
  </code></pre>
  
  <p>The second piece of code is:</p>
  
  <pre><code>    void App::App_BackRequested(
      Platform::Object^ sender, 
      Windows::UI::Core::BackRequestedEventArgs^ e)
      {
      Frame^ rootFrame = dynamic_cast&lt;Frame^&gt;(Window::Current-&gt;Content);
      if (rootFrame == nullptr)
      return;
  
      // Navigate back if possible, and if the event has not
      // already been handled.
      if (rootFrame-&gt;CanGoBack &amp;&amp; e-&gt;Handled == false)
          {
              e-&gt;Handled = true;
              rootFrame-&gt;GoBack();
          }
      }
  </code></pre>
  
  <p>Please help me in this matter and tell me how do I implement this code in my UWP App. Thanks</p>
  
  <p>Source: <a href="https://msdn.microsoft.com/en-us/library/windows/apps/mt465734.aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/windows/apps/mt465734.aspx</a></p>