开发者

What are interaction triggers?

开发者 https://www.devze.com 2023-01-13 10:06 出处:网络
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_%28

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_开发者_C百科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 :)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号