title: Button Command CanExecute not called when property changed
body: <p>I have a form with a textbox and a button.</p>
  
  <p>When that textbox has it's value changed, the button command doesn't call the CanExecute method of it's command.</p>
  
  <p>The command parameter is set but doesn't seem to change.
  After load the window, the button remains disabled.</p>
  
  <pre><code>&lt;TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" /&gt;
  &lt;Button Content="Save" Command="{Binding SaveChangesCommand}" CommandParameter="{Binding Name}" /&gt;
  </code></pre>
  
  <p>I know the binding is working because I created a behavior that receives a target binding and raise the CanExecute when the the binding changes.</p>
  
  <p>With this behavior, the CanExecute is called normally.</p>
  
  <pre><code>&lt;Button Content="Save" Command="{Binding SaveChangesCommand}"&gt;
      &lt;i:Interaction.Behaviors&gt;
          &lt;behaviors:CallCommandCanExecuteWhenBindingChange Target="{Binding Name}" /&gt;
      &lt;/i:Interaction.Behaviors&gt;
  &lt;/Button&gt;
  </code></pre>
  
  <p>ViewModel:</p>
  
  <pre><code>public class EditViewModel : INotifyPropertyChanged
  {
      private string _name;
  
      public EditViewModel()
      {
          SaveChangesCommand = new DelegateCommand(p =&gt; SaveChanges(), p =&gt; CanSaveChanges());
      }
  
      public string Name
      {
          get { return _name; }
          set
          {
              if (value == _name) return;
              _name = value;
              OnPropertyChanged();
          }
      }
  
      public DelegateCommand SaveChangesCommand { get; private set; }
  
      private void SaveChanges()
      {
      }
      private bool CanSaveChanges()
      {
          return !string.IsNullOrWhiteSpace(Name);
      }
  }
  </code></pre>
  
  <p>DelegateCommand:</p>
  
  <pre><code>public interface IBaseCommand : ICommand
  {
      void OnCanExecuteChanged();
  }
  
  public class DelegateCommand : IBaseCommand
  {
      private readonly Action&lt;object&gt; _execute;
      private readonly Func&lt;object, bool&gt; _canExecute;
  
      public DelegateCommand(Action&lt;object&gt; execute, Func&lt;object, bool&gt; canExecute)
      {
          _execute = execute;
          _canExecute = canExecute;
      }
  
      public event EventHandler CanExecuteChanged;
  
      public bool CanExecute(object parameter)
      {
          return _canExecute(parameter);
      }
      public void Execute(object parameter)
      {
          _execute(parameter);
          OnCanExecuteChanged();
      }
  
      public void OnCanExecuteChanged()
      {
          var handler = CanExecuteChanged;
          if (handler != null)
              handler(this, EventArgs.Empty);
      }
  }
  </code></pre>
  
  <p>CallCommandCanExecuteWhenBindingChange:</p>
  
  <pre><code>public class CallCommandCanExecuteWhenBindingChange : Behavior&lt;FrameworkElement&gt;
  {
      public static readonly DependencyProperty&lt;CallCommandCanExecuteWhenBindingChange, object&gt; TargetProperty;
      private ICommandBase _command;
  
      static CallCommandCanExecuteWhenBindingChange()
      {
          var dependency = new DependencyRegistry&lt;CallCommandCanExecuteWhenBindingChange&gt;();
  
          TargetProperty = dependency.Register(b =&gt; b.Target, s =&gt; s.OnTargetChange());
      }
  
      public object Target
      {
          get { return TargetProperty.Get(this); }
          set { TargetProperty.Set(this, value); }
      }
  
      private void OnTargetChange()
      {
          if (_command == null &amp;&amp; AssociatedObject != null)
          {
              var field = AssociatedObject.GetType().GetProperty("Command");
              _command = (IBaseCommand)field.GetValue(AssociatedObject);
          }
  
          if (_command != null)
              _command.OnCanExecuteChanged();
      }
  }
  </code></pre>
  
  <p>Does anyone know why the button doesn't call the CanExecute?</p>