In WPF, can I specify multiple routable events for a single event trigger?

I have an event trigger that I want to fire in response to two different routed events. I do not want to repeat the event response code (in XAML) twice. Can I specify multiple routable events for a single event trigger declaration?

An example of a single event:

<Style.Triggers>
    <EventTrigger RoutedEvent="Button.MouseEnter">
        <--XAML MAGIC-->
        ...
+3
source share
1 answer

Sorry ... The WPF implementation of EventTrigger only allows one routable event.

Usually you start a storyboard from a routed event. I would suggest the following tradeoff:

<!--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>

.

, !

+5

Source: https://habr.com/ru/post/1704891/


All Articles