views:

837

answers:

1

Does WPF support using a triggers that respond to routed events but only given a condition is met?

For example, WPF supports triggering on routed events through Event Triggers. ie:

<Button>
  <Button.Triggers>
    <EventTrigger RoutedEvent="Click">
      ...
    </..
  </..
</..

However I am looking for the trigger to go off only given a certain condition is met. Normally you use MultiTriggers for meeting multiple conditions. ie:

<Button>
  <Button.Triggers>
    <MultiDataTrigger>
      <MultiDataTrigger.Conditions>
         <Condition Binding="..." Value="..."/>
         <Condition Binding="..." Value="..."/>
      </..
    </..
  </..
</..

However neither the MultiTrigger or MultiDataTrigger seem to support triggering on routed events. Is it even possible to mix these two concepts of routed events and conditions in XAML?

+1  A: 

I don't think it is. Not the way you're thinking about it, anyway.

The MultiTrigger and MultiDataTrigger are triggered when multiple properties have the matching values at the same time. This is something that can easily happen because it is based on state. It's based on values that stay the same, at least for a while.

Events on the other hand, happen and then are gone. How could you react two multiple events, when they not occurring at the same moment?

You would have to use your EventTriggers -- perhaps in set-enter/set-leave pairs -- to set the state of certain properties (attached properties sound good here), and then create a MultiTrigger that looked at those properties.

Joel B Fant
I agree, and I would add that most RoutedEvents which indicate a change in state have properties that correspond to them and can be used in a MultiTrigger.
Robert Macnee