title: Setting DataContext on ViewModel
body: <p>The Page2.xaml uses SampleData, which works perfectly in the designer.
  When I'm calling Page2.xaml from MainPage.xaml, and try to set loaded data for Page2.xaml </p>
  
  
  
  <pre><code>public Page2()
  {
      InitializeComponent();
  
      if (!App.Page2VM.IsDataLoaded)
      {
          App.Page2VM.LoadData();
      }
  
      App app = (App)Application.Current;
      this.DataContext = App.Page2VM; &lt;-- error here
  }
  </code></pre>
  
  <p>I got an error. This code works for MainPage.xaml with MainVM. Why?</p>