title: C# WPF close new user control
body: <p>I am new to c#. I have created main windows that I am adding usercontrols to switch between screens with command:</p>
  
  <pre><code>Switcher.Switch(new NewPage());
  </code></pre>
  
  <p>The class Switcher is:</p>
  
  <pre><code>public static class Switcher
      {
          public static MainWindow pageSwitcher;
  
          public static void Switch(UserControl newPage)
          {
              pageSwitcher.Navigate(newPage);
          }
  
          public static void Switch(UserControl newPage, object state)
          {
              pageSwitcher.Navigate(newPage, state);
          }
  
      }
  </code></pre>
  
  <p>But how to I exit the user control? I wish to finish it (like back button). I can use:</p>
  
  <pre><code>Switcher.Switch(new PreviousPage());
  </code></pre>
  
  <p>but it will keep the new page in memory and will not release it.</p>
  
  <p>Example of NewPage class:</p>
  
  <pre><code>namespace MyProject.Screens
  {
  
      public partial class NewPage : UserControl
      {
          public NewPage()
          {
              InitializeComponent();
          }
  
          private void back_button_Click_(object sender, RoutedEventArgs e)
          {
             //what to put here?
          }
      }
  }
  </code></pre>