title: WPF Change View from a User Control MVVM
body: <p>I'm trying to navigate from one <code>View Model</code> to another without any side panel.</p>
  
  <p>For example, I have a <code>Main Window View</code>, this is where I load my <code>User Control</code>.</p>
  
  <p>I have tried to access the static instance from the <code>MainViewModel</code> to change the Views, but it's not working.</p>
  
  <p><strong>MainWindow.xaml</strong></p>
  
  <pre><code>&lt;Window.Resources&gt;
  
      &lt;DataTemplate DataType="{x:Type vm:FirstViewModel}"&gt;
          &lt;v:FirstView/&gt;
      &lt;/DataTemplate&gt;
  
      &lt;DataTemplate DataType="{x:Type vm:SecondViewModel}"&gt;
          &lt;v:SecondView/&gt;
      &lt;/DataTemplate&gt;
  
  &lt;/Window.Resources&gt;
  &lt;ContentControl Content="{Binding CurrentViewModel}"/&gt;
  </code></pre>
  
  <p><strong>MainViewModel.cs</strong></p>
  
  <pre><code>class MainviewModel : ObservableObject
  {
      private ObservableObject _currentViewModel = new FirstViewModel();
      public ObservableObject CurrentViewModel
      {
          get { return _currentViewModel; }
          set
          {
              _currentViewModel = value;
              RaisePropertyChangedEvent("CurrentViewModel");
          }
      }
  
      private static MainViewModel _instance = new MainViewModel();
      public static MainViewModel Instance { get { return _instance; } }
  }
  </code></pre>
  
  <p>Here, I have my <code>FirstView</code>, it just contains a button and several other UI designs</p>
  
  <p><strong>FirstView.xaml</strong></p>
  
  <pre><code>&lt;Button Command="{Binding goToSecondView}" /&gt;
  </code></pre>
  
  <p><strong>FirstViewModel.cs</strong></p>
  
  <pre><code>class FirstViewModel : ObservableObject
  {
      public ICommand goToSecondView
      {
          get
          {
              return new DelegateCommand(() =&gt;
              {
                  MainViewModel.Instance.CurrentViewModel = new SecondViewModel();
              });
          }
      }
  }
  </code></pre>
  
  <p>And I have a <code>SecondView</code>, which is similar to <code>FirstView</code>, just that it navigates to <code>FirstView</code></p>
  
  <p>I have tried searching for a solution, but so far, I have only managed to find examples that shows buttons on a panel which then allow switching of the <code>User Control</code> from clicking those button.</p>
  
  <p>What I am trying to achieve is to enable switching of <code>User Control</code> via the buttons on the <code>User Control</code> itself, without any side panel.</p>
  
  <p>Any help would be very much appreciated and would definitely aid me in my future projects.</p>
  
  <p>Thank You.</p>