tags:

views:

193

answers:

1

RelayCommands overriding the "IsEnabled" of my buttons.

Is this is a bug? Here is xaml from my View and code from my ViewModel

<Button Grid.Column="0" Content="Clear" IsEnabled="False" cmd:ButtonBaseExtensions.Command="{Binding ClearCommand}"  />    

public RelayCommand ClearCommand
    {
       get { return new RelayCommand(() => MessageBox.Show("Clear Command")); }
    }

Notice I hardcoded the IsEnabled="False" in my xaml. This value is completely ignored (button always enabled).

I realize that RelayCommand have a CanExecute overload but I did want to use this as I want to do more than just have a disabled button.

+1  A: 

Hi,

That's an interesting point. You are right, the IsEnabled property gets overriden. I guess an improvement could be to ignore the IsEnabled property if the CanExecute delegate is not set in the constructor... I will consider it in a next version.

In the mean time, use the CanExecute delegate and set it to return false always.

public RelayCommand ClearCommand
{
   get { return new RelayCommand(
       () => MessageBox.Show("Clear Command"),
       () => false); }
}

Cheers, Laurent

LBugnion
Thanks! I think that change would make sense. Your toolkit is great btw.
vidalsasoon