title: WPF Close window with MVVM from ViewModel class
body: <p>In my view I have:</p>
  
  <pre><code>&lt;Button Grid.Column="2" x:Name="BackBtn" Content="Powrót" Command="{Binding ClickCommand}" Width="100" Margin="10" HorizontalAlignment="Right"/&gt;
  </code></pre>
  
  <p>Then, in ViewModel :</p>
  
  <pre><code>public ICommand ClickCommand
  {
      get
      {
  
          return _clickCommand ?? (_clickCommand = new CommandHandler(() =&gt; MyAction(), _canExecute));
      }
  }
  
  private void MyAction()
  {
      MainWindow mainWindow = new MainWindow(); // I want to open new window but how to close current?
      mainWindow.Show();
      // how to close old window ?
  }
  
  namespace FirstWPF
  {
      public class CommandHandler : ICommand
      {
          private Action _action;
          private bool _canExecute;
          public CommandHandler(Action action, bool canExecute)
          {
              _action = action;
              _canExecute = canExecute;
          }
  
          public bool CanExecute(object parameter)
          {
              return _canExecute;
          }
  
          public event EventHandler CanExecuteChanged;
  
          public void Execute(object parameter)
          {
              _action();
          }
      }
  }
  </code></pre>
  
  <p>I have no idea how to manage that problem, I want to close current window form ViewModel, because I am opening a new one.</p>