tags:

views:

37

answers:

1

Hello,

I am reading Shawn Wildermuth's article on architecting Silverlight applications using MVVM light :- http://wildermuth.com/2010/01/02/Architecting_SL4_Apps_with_RIA_Services_MEF_and_MVVM_-_Part_4_%28of_3%29

I just wonder what is the difference between :-

<Button
Content="Previous Page" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<i:InvokeCommandAction CommandName="PreviousPage"/>
<ei:CallMethodAction TargetObject="{Binding ElementName=grid}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button> 

And

<Button Command="{Binding PreviousPage}"
Grid.Row="0"
Content="Previous Page" />

When would you specifically use triggers?

Thanks in advance :)

+4  A: 

The main reason to use the trigger over the command binding is if you want the trigger to fire on an event other than Click. If you need a command to fire on a mouse over instead of on the button click you would need to use the trigger with the EventName set to handle mouse overs.

Commands as implemented on the controls themselves are very limited. They cover the basic cases well but they aren't very flexible. The triggers give you slightly more flexibility.

Stephan