locked
AppbarButton Click command using binding RRS feed

  • Question

  • I had used a simple button as AppBarButton when I was using VS 2012, now that I' retargeting my app to windows 8.1 and I'm replacing regular button with AppBarButton now.

    When I used regular button and I can wire the Command (click event) bound to my view model and thus tried to avoid writing code in code-behind file of the XAML.

    Now I do not see that option for AppBarButton, how can I still use the ViewModel to bind the clieck event

    Thanks

    Monday, January 27, 2014 6:46 PM

Answers

  • AppBarButton inherits the Command property from ButtonBase. So in an MVVM app you can (still) write:

    <AppBarButton Command="{Binding RunCommand}"
                                  Icon="Play"
                                  Label="Run" />
    In the bound ViewModel you need to specify the RunCommand as ICommand, and implement it with a field of a 3rd party RelayCommand or DelegateCommand.

    • Marked as answer by biprism Monday, January 27, 2014 8:00 PM
    Monday, January 27, 2014 7:08 PM

All replies

  • AppBarButton inherits the Command property from ButtonBase. So in an MVVM app you can (still) write:

    <AppBarButton Command="{Binding RunCommand}"
                                  Icon="Play"
                                  Label="Run" />
    In the bound ViewModel you need to specify the RunCommand as ICommand, and implement it with a field of a 3rd party RelayCommand or DelegateCommand.

    • Marked as answer by biprism Monday, January 27, 2014 8:00 PM
    Monday, January 27, 2014 7:08 PM
  • Oh, OK so even though it is not available in designer I can still do it like the way I did with button. Yes, I use RelayCommand that is available in template generated code.

    Thanks

    Monday, January 27, 2014 8:00 PM