title: Why WPF button's command's CanExecute method is not called even if I call CommandManager.InvalidateRequerySuggested()?
body: <p>I'm facing the same issue reported in these questions:</p>
  
  <p><a href="https://stackoverflow.com/questions/28343632/button-command-canexecute-not-called-when-property-changed">Button Command CanExecute not called when property changed</a></p>
  
  <p><a href="https://stackoverflow.com/questions/3805336/how-can-i-force-a-textbox-change-to-enable-my-command-in-wpf/3806552#3806552">How can I force a textbox change to enable my command in WPF?</a></p>
  
  <p>(that briefly is: <strong>my command-linked button doesn't get enabled when it should</strong>) but with a slight difference: <strong>I already tried to invoke CommandManager.InvalidateRequerySuggested(), with no result</strong>.</p>
  
  <p>The weirdest thing is that the button gets enabled only as soon as I "trigger" any event on the window, like clicking with the mouse in any point of the window.</p>
  
  <p>Here is the code to reproduce the issue:</p>
  
  <pre><code>&lt;Window x:Class="WpfApplication1.MainWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:local="clr-namespace:WpfApplication1"
      mc:Ignorable="d"
      Title="MainWindow" Height="350" Width="525"&gt;
  &lt;Window.CommandBindings&gt;
      &lt;CommandBinding Command="{x:Static local:Commands.RunTask}" x:Name="cmdRunTask" CanExecute="CanExecuteRunTask" Executed="ExecuteRunTask"&gt;    &lt;/CommandBinding&gt;
      &lt;CommandBinding Command="{x:Static local:Commands.PushButton}" x:Name="cmdPushButton" CanExecute="CanPushButton" Executed="PushButton"&gt;&lt;/CommandBinding&gt;
  &lt;/Window.CommandBindings&gt;
  &lt;StackPanel&gt;
      &lt;Button Content="Run task"
                  x:Name="runButton"
                  Command="{x:Static local:Commands.RunTask}"
                  &gt;
      &lt;/Button&gt;
      &lt;ProgressBar x:Name="progress"
                       Value="{Binding Path=Value, Mode=OneWay}"
                   Height="30"
                       &gt;
      &lt;/ProgressBar&gt;
      &lt;Button Content="Press me if you dare"
                  x:Name="pushButton"
                  Command="{x:Static local:Commands.PushButton}"
                  &gt;
      &lt;/Button&gt;
  &lt;/StackPanel&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>using System;
  using System.ComponentModel;
  using System.Threading.Tasks;
  using System.Windows;
  using System.Windows.Controls;
  using System.Windows.Input;
  
  namespace WpfApplication1
  {
      public partial class MainWindow : Window
      {
          public MainWindow()
          {
              DataContext = new Model();
              ((Model)DataContext).PropertyChanged += DataContext_PropertyChanged;
              InitializeComponent();
          }
  
          private void DataContext_PropertyChanged(object sender, PropertyChangedEventArgs e)
          {
              switch (e.PropertyName)
              {
                  case "Ready":
                      CommandManager.InvalidateRequerySuggested();
                      break;
              }
          }
  
          void CanExecuteRunTask(object sender, CanExecuteRoutedEventArgs e)
          {
              e.CanExecute = true;
          }
  
          void ExecuteRunTask(object sender, ExecutedRoutedEventArgs e)
          {
              ((Model)DataContext).RunLongTask();
          }
  
          void CanPushButton(object sender, CanExecuteRoutedEventArgs e)
          {
              e.CanExecute = ((Model)DataContext).Ready;
          }
  
          void PushButton(object sender, ExecutedRoutedEventArgs e) { }
      }
  
      public static class Commands
      {
          public static readonly RoutedUICommand RunTask = new     RoutedUICommand();
          public static readonly RoutedUICommand PushButton = new     RoutedUICommand();
      }
  
      public class Model : INotifyPropertyChanged
      {
          private bool _ready = false;
          public bool Ready
          {
              get { return _ready; }
              set
              {
                  _ready = value;
                  RaisePropertyChanged("Ready");
              }
          }
  
          private int _value = 0;
          public int Value
          {
              get { return _value; }
              set
              {
                  _value = value;
                  RaisePropertyChanged("Value");
              }
          }
  
          public async void RunLongTask()
          {
              await RunLongTaskAsync();   
          }
          private Task RunLongTaskAsync()
          {
              this.Ready = false;
              Task t = new Task(() =&gt; {
                  for (int i = 0; i &lt;= 100; i++)
                  {
                      Value = i;
                      System.Threading.Thread.Sleep(20);
                  }
                  this.Ready = true;
              });
              t.Start();
              return t;
          }
  
          public event PropertyChangedEventHandler PropertyChanged;
          protected void RaisePropertyChanged(string propertyName)
          {
              if (PropertyChanged != null)
                  PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
          }
      }
  }
  </code></pre>