EventToCommand Trigger Extension

May 31, 2012 at 9:20 AM


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)
   // ---------- 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 3:09 PM

The DisableAssociatedObjectOnCannotExecute doesn't work for you?

May 31, 2012 at 9: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 7: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 7: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 12:52 PM

Many Thanks!