Improvement to EventToCommandTrigger

Aug 13, 2015 at 8:24 AM
I have an improvement for the EventToCommandTrigger.

Problem is, that a Control with Interaction Triggers and a Binding to a Command like this:
<i:Interaction.Triggers>
    <i:EventTrigger EventName="MouseLeftButtonDown">
        <cinchV2:EventToCommandTrigger Command="{Binding DataContext.OpenBrowserViewerCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type machineDocumentsViewModel:MachineDocumentsViewModel}}}" />
    </i:EventTrigger>
</i:Interaction.Triggers>
My other Triggers, which try to manipulate the IsEnabled Property of my Control are useless, because the IsEnabled Prop is always overwritten.

So I made a small Improvement:
  • The EnableDisable Mechanism inside the EventToCommandTrigger is asking for a Property before it is setting the IsEnabled prop of the control.
New Usage:
<cinch:EventToCommandTrigger EnableDisableByCommand="False" Command="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type UserControl}}, Path=OpenToolSelectorCommand}" />
So this control is never enabled nor disabled by the EventToCommandTrigger.

My Patch:
139,140c139
<             if (EnableDisableByCommand)
<                 AssociatedObject.IsEnabled = Command.CanExecute(this.CommandParameter);
---
>             AssociatedObject.IsEnabled = Command.CanExecute(this.CommandParameter);
198d196
< 
209,225d206
<         #endregion
< 
<         #region Properties
<         private bool _enableDisableByCommand = true;
< 
<         public bool EnableDisableByCommand
<         {
<             get
<             {
<                 return _enableDisableByCommand;
<             }
<             set
<             {
<                 _enableDisableByCommand = value;
<             }
<         }
<