title: When is CanExecute called?
body: <p>In the demo, I have a button to toggle a bool field <code>isAsking</code>. I create a command which can execute only when <code>isAsking==true</code>.</p>
  <p>Once I press the Toggle button, <code>okButton.IsEnable</code> changes immediately, which indicates the command finds the change of <code>isAsking</code>.</p>
  <p>I feel very confused why the command object notices the change of a field. When <code>CanExecute</code> will be called?</p>
  <p>Although writting WPF application for some time, I'm new to WPF Command. Please give an explanation to this case and if possible, point out some related articles or blogs (I've already read too many articles talking about cut/paste command).</p>
  <pre><code>&lt;Window xmlns=&quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;
          xmlns:x=&quot;http://schemas.microsoft.com/winfx/2006/xaml&quot;
          x:Class=&quot;WpfApplication1.MainWindow&quot;
          Title=&quot;MainWindow&quot; Height=&quot;350&quot; Width=&quot;525&quot; x:Name=&quot;mainWindow&quot; &gt;
      &lt;StackPanel&gt;
          &lt;Button Name=&quot;okButton&quot; Content=&quot;Ok&quot; /&gt;
          &lt;Button Content=&quot;Toggle&quot;  Click=&quot;Button_Click_1&quot;/&gt;
      &lt;/StackPanel&gt;
  &lt;/Window&gt;
  </code></pre>
  <p>Code-behind:</p>
  <pre><code>public partial class MainWindow : Window
  {
      private bool isAsking;
  
      public MainWindow()
      {
          InitializeComponent();
  
          CommandBinding cb = new CommandBinding();
          cb.Command = okCommand;
          cb.CanExecute += CanOKExecute;
          cb.Executed += cb_Executed;
          mainWindow.CommandBindings.Add(cb);
          okButton.Command = okCommand;
      }
  
      private RoutedCommand okCommand = new RoutedCommand(&quot;ok&quot;, typeof(MainWindow));
  
  
      void cb_Executed(object sender, ExecutedRoutedEventArgs e)
      {
         
      }
  
      void CanOKExecute(object sender, CanExecuteRoutedEventArgs e)
      {
          e.CanExecute = isAsking;
      }
  
      private void Button_Click_1(object sender, RoutedEventArgs e)
      {
          isAsking = !isAsking;
      }
  }
  </code></pre>