Search code examples
silverlighteventsxamleventtrigger

Silverlight. The order of triggers invocation


There is a Silverlight UserControl which got an MouseLeftButtonUp event. In xaml I add two triggers for this event. In which order Silverlight xaml-parser will parse and attach those triggers and can I be sure that trigger above will invoke first?

...
    <i:Interaction.Triggers>
      <i:EventTrigger EventName="MouseLeftButtonUp">
         <i:InvokeCommandAction Command="{StaticResource someCommand}"/>
         <AttachedBehaviors:SomeBehavior Parameter="Apple"/>
      </i:EventTrigger>
    </i:Interaction.Triggers>
...


UPDATE: Found connected issue In WPF, does the order of Triggers matter? which says:

WPF is processing triggers in declared order.

Hope, Silverlight behave exactly that same.


Solution

  • Even if the order is defined I wouldn't do this. Add the order you want to the handler of the command.

    void someCommand_Executed()
    {
        DoFirstThing();
        DoSecondThing();
    }
    

    This kind of code will cause pain in the long run because the order is not easily enforced and you are creating a dependency between two methods.