title: Call view model method from view (xaml.cs)
body: <p>I have a question on calling a method of view model from view (xaml.cs). Any suggestions would be appreciated.</p>
  
  <p>The method works in view model since if I call the method in view model constructor, I will be able to see the data in DataGrid. But when I call the method in view (xaml.cs), the DataGrid is empty.</p>
  
  <p>In the view part, I have the code snippet below: (xaml.cs part)</p>
  
  <pre><code> private ShellViewModel viewModel = new ShellViewModel();
  
          public ShellView()
  
          {
  
               this.DataContext = viewModel;
  
               InitializeComponent();
  
          }
  
  ......
  
          private void Button_Click(object sender, RoutedEventArgs e)
  
          {
  
               viewModel.Init();
  
          }// @@cannot call this method successfully
  </code></pre>