title: How to find WPF Page in navigation history to prevent opening the page again
body: <p>How do I determine if a WPF page is still in the navigation history of WPF frame and then navigate back to it?</p>
  
  <p><strong>Summary:</strong></p>
  
  <p>My WPF application uses a single MainWindow containing two Frames one for menu layout and the other for display content.  I am using MVVM pattern with content displayed as WPF pages as views with as little code as possible behind each view/page.</p>
  
  <p>The content frame (shown in red) has a NavigationUI visible.
  <a href="https://i.stack.imgur.com/g44CX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g44CX.png" alt="enter image description here"></a></p>
  
  <p>XAML:</p>
  
  <p><a href="https://i.stack.imgur.com/MZCeZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MZCeZ.png" alt="enter image description here"></a></p>
  
  <p>Here is typical code to create WPF page and display it in the main window from a static helper class:</p>
  
  <pre><code>public static void ShowPeriodicTable()
  {
    var page = new Views.PeriodicTable();
    (Application.Current.MainWindow as MainWindow).ContentArea.Navigate(page);
  }
  </code></pre>
  
  <p>This code will load the same page over and over even if it is already loaded.</p>
  
  <p>I've made the following change to detect if the current page displayed in the MainWindow.ContentArea (frame) before creating and navigating to the page.  </p>
  
  <pre><code>public static void ShowPeriodicTable()
      {                   
          var currentPage = ((DRC_SQLITE.MainWindow)Application.Current.MainWindow).ContentArea.Content;
          if (currentPage == null || (currentPage != null &amp;&amp; currentPage.GetType().Name != "PeriodicTable"))
          {
              var page = new Views.PeriodicTable();
              (Application.Current.MainWindow as MainWindow).ContentArea.Navigate(page);
          }
      }
  </code></pre>
  
  <p><strong>Question:</strong></p>
  
  <p>How do detect if the page that is about to be opened exists in the navigation history but is not the current page in the frame.  In the image below, the settingPage was opened twice.  This is the scenario I want to eliminate to better manage memory usage of the application.  </p>
  
  <p><a href="https://i.stack.imgur.com/wHhj9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wHhj9.png" alt="enter image description here"></a></p>