EventToCommand Trigger Extension

May 31, 2012 at 10:20 AM

Hi,

it would be very helpful if you could add a property to the EventToCommand trigger, which

allows to specify if the IsEnabled property of the associated object should be modified at all.

Line 142 EventToCommand.cs:

 private void UpdateElementState()
{
   if (this.AssociatedObject == null || this._command == null)
       return;
   // ---------- modificiation
   if (this.MustToggleIsEnabledOnAssociatedObject)
   // ---------- modificiation
   {
        bool? nullable = this._disableAssociatedObjectOnCannotExecute;
        this.AssociatedObject.IsEnabled = (nullable.HasValue ? (nullable.GetValueOrDefault() ? 1 : 0) : 0) == 0 || this.command.CanExecute(this._commandParameter);
    }
}

many thanks!
May 31, 2012 at 4:09 PM

The DisableAssociatedObjectOnCannotExecute doesn't work for you?

May 31, 2012 at 10:18 PM

Hi Geert,

the problem is that the EventToCommand always overwrites the IsEnabled value/binding

no matter if requested or not. I have situations where IsEnabled is binded to

a different property, the EventToCommand should always be executed and it should

not modify/touch the IsEnabled property in any way.

The DisableAssociatedObjectOnCannotExecute does not prevent the modification of

the IsEnabled value/binding.

Jun 3, 2012 at 8:48 AM

Now I see what you mean. I will create another property on the EventToCommand trigger. However, keep in mind that it is best to always bind the IsEnabled state to the logic of a command.

Jun 3, 2012 at 8:52 AM

Implemented, here are the details:

(*) If EventToCommand.DisableAssociatedObjectOnCannotExecute is null or false, it will never touch the IsEnabled property of the associated object so it can be bound to other properties / values

Jun 3, 2012 at 1:52 PM

Many Thanks!