当前位置:编程学习 > wap >>

使用MVVM绑定AppBar事件

最近在做一个项目,使用到MVVM,在appbar事件绑定时候发现不知道怎么绑定,查阅资料发现时可以绑定的,需要借助到AppBarUtils,可以到这里http://appbarutils.codeplex.com/下载到。


具体使用方法如下:

首先在xmal中添加引用

xmlns:appbar="clr-namespace:AppBarUtils;assembly=AppBarUtils"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
然后viewmodel重添加Command


/// <summary>
/// 刷新Command
/// </summary>
public ICommand RefreshCommand
{
            get;
            set;
 }

最后在xmal中添加appbar的绑定


<phone:PhoneApplicationPage.ApplicationBar>
     <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
        <shell:ApplicationBarIconButton IconUri="/Resource/icons/appbar.refresh.png" Text="refresh"/>
     </shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
<i:Interaction.Behaviors>
   <appbar:AppBarItemCommand Id="refresh" Text="刷新" Command="{Binding Path=RefreshCommand}"></appbar:AppBarItemCommand>
</i:Interaction.Behaviors>

 


摘自 Better.Chaner
 

补充:移动开发 , Windows Phone ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,