title: WPF how to update CanExecute
body: <p>I have the following question. </p>
  
  <p>I have the following simple xaml: </p>
  
  <pre><code>&lt;TextBox Name="NameBox" Text ="{Binding Name}" /&gt;
  &lt;Button Content="Save" Command="{Binding SaveCommand}" CommandParameter="{Binding Entity}"  /&gt;
  </code></pre>
  
  <p>And i bind DataContext of this Window to following View Model</p>
  
  <pre><code>public class MyViewModel
  {
      public SimpleModel Entity { get; set; }
  
      private ICommand _saveCommand;
  
      public ICommand SaveCommand { get { return _saveCommand ?? (_saveCommand = new MyCommand(OnSaveItem, parameter =&gt; CanSaveItem())); } }
  
      public void OnSaveItem(object parameter) 
      {
          // some code
      }
  
      public virtual bool CanSaveItem()
      {
          return !String.IsNullOrWhiteSpace(Entity.Name);
      }
  
  }      
  </code></pre>
  
  <p>SimpleModel is </p>
  
  <pre><code>public class SimpleModel
  {        
      public int Id { get; set; }
  
      public string Name { get; set; }       
  }
  </code></pre>
  
  <p>This code works mostly correct but i can not 
  make method CanSaveItem to work properly. I don't know how to tell to SaveCommand that properties of ViewModel was changed. I know that i have to use CanExecuteChanged or CommandManager.InvalidateRequerySuggested and i tried to use their some times but i don't know how to do it properly and it didn't take an effect. Could you help me with this problem? </p>
  
  <p>UPD.</p>
  
  <pre><code>public class MyCommand : ICommand
  {        
      public MyCommand(Action&lt;object&gt; execute, Predicate&lt;object&gt; canExecute)
      {
          _canExecute = canExecute;
          _execute = execute;
      }
  
      public bool CanExecute(object parameter)
      {
          return _canExecute(parameter);
      }
  
      public void Execute(object parameter)
      {                       
          _execute(parameter);
      }
  
      public event EventHandler CanExecuteChanged
      {
          add { CommandManager.RequerySuggested += value; }
          remove { CommandManager.RequerySuggested -= value; }
      }
  
      private readonly Predicate&lt;object&gt; _canExecute;
  
      private readonly Action&lt;object&gt; _execute;
  }
  </code></pre>