How to move my RoutedCommand handler from View-codebehind to ViewModel? How to move my RoutedCommand handler from View-codebehind to ViewModel? wpf wpf

How to move my RoutedCommand handler from View-codebehind to ViewModel?


You'll expose a property off your ViewModel that references the command.

class MyViewModel{    public RoutedCommand SaveCmd{ get{ return Commands.SaveCustomer; } }}  

Then in the XAML

<Button Command="{Binding SaveCmd}" />

However you might find it easier to use the RelayCommand so that you can define the actual command logic in your model as well.