CanExecute doesn't appear to work

Jan 9, 2012 at 9:20 AM

Hi,

We have a WPF project with a simple button attached to a command...

    
    <telerik:RadButton Command="{Binding Path=AddUserCommand}"
                       Content="Add new user"
                       Height="Auto"
                       HorizontalAlignment="Left"
                       Margin="249,43,0,0"
                       Name="radButton3"
                       VerticalAlignment="Top"
                       Width="Auto"
                       CommandParameter="{Binding ElementName=radMaskedTextBox1, Path=Value}" /
The CommandParameter is not really necessary, but we were trying some stuff out.
The command looks like this in the ViewModel...

    private DelegateCommand<string> addUserCommand;

    public DelegateCommand<string> AddUserCommand {
      get {
        return addUserCommand ?? (addUserCommand = new DelegateCommand<string>(AddUser, AddUserCanExecute));
      }
      private set {
        addUserCommand = value;
      }
    }

    private void AddUser(string NewUserName) {
      service.AddUser(NewUserName);
    }

     bool AddUserCanExecute(string NewUserName) {
      return !string.IsNullOrEmpty(CustomerName);
    }

And CustomerName looks like...
  private string customerName;

    public string CustomerName {
      get {
        return customerName;
      }
      set {
        customerName = value;
        NotifyPropertyChanged(m => m.CustomerName);

        AddUserCommand.RaiseCanExecuteChanged();
      }
    }

In the ViewModel constructor we set CustomerName = "";
So, would expect that the button is greyed out initially. But it isn't - any clues?
If I type into the text box that is bound to CustomerName and then delete everything from the 
textbox, the button is greyed out, but not on initial load.
Setting CustomerName to "" does call the "RasieCanExecuteChanged".
BTW, if I don't have the RaiseCanExcuteChanged call, then even when I clear the textbox, the button still remains active - which 
thought was not supposed to be the case for WPF.

Thanks,
Joseph.