使用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>
代码之美
原文地址:https://www.cnblogs.com/betterchaner/p/2523753.html