Reputation: 8273
Intro I'm working with WPF with MVVM-Light application
Goal
I have to invoke two commands from the same event, Is this possible using MVVM.?
Xaml look like this
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<command:EventToCommand Command="{Binding Command1}" PassEventArgsToCommand="False" />
<command:EventToCommand Command="{Binding Command2}" PassEventArgsToCommand="False" />
</i:EventTrigger>
</i:Interaction.Triggers>
Problem
When hooking two commands only one of them is invoked while triggering the event.
Q1 How to invoke two commands in a event?
I have heard about Composite commands in PRISM
For example, the CompositeCommand
class is used in the Stock Trader Reference Implementation (Stock Trader RI) in order to implement the SubmitAllOrders
command represented by the Submit All button in the buy/sell view. When the user clicks the Submit All button, each SubmitCommand
defined by the individual buy/sell transactions is executed.
.
Q2 Is there anything like this in MVVM ?
Upvotes: 2
Views: 1647
Reputation: 21
Try using 2 event triggers:
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<command:EventToCommand Command="{Binding Command1}" PassEventArgsToCommand="False" />
</i:EventTrigger>
<i:EventTrigger EventName="Loaded">
<command:EventToCommand Command="{Binding Command2}" PassEventArgsToCommand="False" />
</i:EventTrigger>
</i:Interaction.Triggers>
Upvotes: 2