title: Navigating from one xaml to another in WPF
body: <p>Despite the fact that I am totally a fresh to WPF, I need to write a code, in which after I click a button, the application should open another xaml. After searching on the web, I did in in the following way:</p>
  
  <p>1.I created two xaml files, namely 'Window1.xaml' and 'Window2.xaml'. </p>
  
  <p>2.In my 'App.xaml' file, I let:</p>
  
  <pre><code>&lt;Application x:Class="DiagramDesigner.App"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        
      StartupUri="Window1.xaml"&gt;
  </code></pre>
  
  <p>3.Then in my 'Window1.xaml', I created a button:</p>
  
  <pre><code>&lt;Button Name="Button" Click="Button_Click_1" MouseEnter="Button_MouseEnter_1" IsDefault="True"
          HorizontalAlignment="Center" VerticalAlignment="Center"&gt;
      Start
  &lt;/Button&gt;
  </code></pre>
  
  <p>4.In my "Windwo1.xaml.cs" file, I created these two functions:</p>
  
  <pre><code>    private void Button_Click_1(object sender, RoutedEventArgs e)
      { 
      }
  
      private void Button_MouseEnter_1(object sender, MouseEventArgs e)
      {
      }
  </code></pre>
  
  <p>5.Then for opening "Window2.xaml" after clicking the button, I changed to:</p>
  
  <pre><code>    private void Button_Click_1(object sender, RoutedEventArgs e)
      { 
          NavigationService service = NavigationService.GetNavigationService(this);
          service.Navigate(new Uri("Window2.xaml", UriKind.RelativeOrAbsolute));
      }
  </code></pre>
  
  <p>But this gives me error, saying the <code>service</code> is null, and the program crashed. I didn't figure out any way to solve this. Any suggestions? Thanks. </p>