title: WPF Page Navigation C# Not Working
body: <p>I am very new to C# and the WPF Architecture. I am trying to create an application with simple page Navigation. I have changed my MainWindow from Window to NavigationWindow. I have also put the following code in MainWindow.xaml.cs</p>
  
  <pre><code> public void View(string newView) 
      {
          Uri view = new Uri(newView, UriKind.Relative);
          NavigationService nav = NavigationService.GetNavigationService(this);
          if (nav != null) 
          {   
              nav.Navigate(view);
          }
          else
          {
              MessageBox.Show("NavNull");
          }
      }
  </code></pre>
  
  <p>I am calling this method from the default source ("HubView.xaml") this is in a folder called "Pages". The code looks like this</p>
  
  <pre><code> public void Button_Click(object sender, RoutedEventArgs e)
      {
          View = @"\Pages\UserAdd.xaml";
          MainWindow mainWindow = new MainWindow();
          mainWindow.View(View);
       }
  </code></pre>
  
  <p>However when I click the button the message box is displayed indicating that nav equals null. I have read through <a href="https://stackoverflow.com/questions/15666075/navigationservice-navigate-null-reference-exception">this</a> question and the subsequent answer, however I still do not fully understand.</p>
  
  <p>Any suggestions would be greatly appreciated!</p>
  
  <hr>
  
  <p><strong><em>Edit:</em></strong></p>
  
  <p>This is the "MainWindow.xaml":</p>
  
  <pre><code>&lt;NavigationWindow x:Class="Container.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      ResizeMode="CanMinimize"
      Title="MainWindow" Height="350" Width="525" Source="Pages/HubView.xaml" WindowStyle="ThreeDBorderWindow" ShowsNavigationUI="False"&gt;
      &lt;/NavigationWindow&gt;
  </code></pre>
  
  <p>As you can see the Window is a Navigation Window.</p>