I have already read Josh Smiths article about binding commands to view model using RelayCommand. However I need to bind ApplicationCommands.Save to a view model so that when a user clicks the save menu item it is handled in the window. How is it possible?
I have already read Josh Smiths article about binding commands to view model using
Share
The best solution I’m aware of us to use a service. For example, an ICommandBindingsProvider like this:
This gets injected into your ViewModel and used like this:
How the service gets injected will be dependent on what MVVM framework you’re using. Most (but not all) support some sort of service injection capabilities. If you need a more concrete code example, look at Onyx which does service injection and has a service that does just this.