wp7 mvvm模式学习之InvokeCommandAction命令绑定

 

 

上一篇说了Command命令绑定,但Command只是按钮类(Button、HyperlinkButton等)所仅有的,其他控件的一些事件怎么实现命令绑定呢?具体的实现和上一篇其实差不多,ViewModel、ICommand接口类的实现等都是一样的,只是xaml的代码有一点不同

 

1、添加Interactivity.dll 引用

 

 

这个dll一般在 C:\Program Files\Microsoft SDKs\Expression\Blend\Windows Phone\v7.1\Libraries 里

 

2、添加命名空间

 

3、xaml里添加绑定代码

1    <TextBlock Text="Test_InvoekeCommandAction" Margin="12,360,19,205" FontSize="28">
2                  <i:Interaction.Triggers>
3                     <i:EventTrigger EventName="MouseLeftButtonUp">
4                         <i:InvokeCommandAction Command="{Binding myCommand}" CommandParameter="Test_InvoekeCommandAction"/>
5                     </i:EventTrigger>
6                 </i:Interaction.Triggers>
7    </TextBlock>

第3行 的 EventName 表示事件的名称
第4行 的 i:InvokeCommandAciton 表示触发器绑定到的具体内容

 

源代码下载:http://www.hugwp.com/forum.php?mod=viewthread&tid=4066&page=1&extra=#pid22581

 

posted @ 2012-07-08 20:39  仙外仙  阅读(1127)  评论(0编辑  收藏  举报