虚位以待(AD)
虚位以待(AD)
首页 > 软件编程 > WindowsPhone/WindowsMobile > 使用MVVM绑定AppBar事件

使用MVVM绑定AppBar事件
类别:WindowsPhone/WindowsMobile   作者:码皇   来源:互联网   点击:

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

最近在做一个项目,使用到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
 

相关热词搜索: 使用 MVVM 绑定