views:

515

answers:

1

I have an event trigger that I want to be fired in response to two different routed events. I don't want to repeat the event response code (in XAML) twice. Can I specify multiple routed events for a single event trigger declaration?

Example of a single event:

<Style.Triggers>
    <EventTrigger RoutedEvent="Button.MouseEnter">
        <--XAML MAGIC-->
        ...
+2  A: 

Sorry... WPF's implementation of the EventTrigger only allows one routed event.

Typically you would be firing a storyboard from a routed event. I would suggest the following compromise:

<!--Define a storyboard as a resource-->
<Storyboard x:Key="MyStoryboard1">
   <!--Many properties and etc...-->
</Storyboard>

<Style.Triggers>
   <EventTrigger RoutedEvent="Button.MouseEnter">
      <BeginStoryboard Storyboard="{StaticResource MyStoryboard1}">
         <!--Other properties/name if necessary-->
      </BeginStoryboard>
   </EventTrigger>
   <EventTrigger RoutedEvent="Button.MouseDown">
      <BeginStoryboard Storyboard="{StaticResource MyStoryboard1}">
         <!--Other properties/name if necessary-->
      </BeginStoryboard>
   </EventTrigger>
</Style.Triggers>

The concept is to reduce duplicate code by sharing resources.

Hope this helps!

Josh G
Thanks, I can live with that. It actually fits pretty well with my intentions.
j0rd4n