Use Built in WPF commands with ViewModel?

WPF's built-in ApplicationCommands and the like were not originally designed with MVVM in mind, so they don't really match up when you try to put them in the ViewModel.

WPF's built-in ApplicationCommands and the like were not originally designed with MVVM in mind, so they don't really match up when you try to put them in the ViewModel. In WPF 4 it is now possible to bind InputCommands to your ViewModel: tomlev2.wordpress.com/2009/10/26/vs2010-... An alternative is to use a DelegateCommands, which you can implement on your own or get from a library like Prism. You can define the DelegateCommand as an object in your viewmodel and bind to it from your view.

Once you have the binding working you define what the command does in your viewmodel code.

I'm guessing that using either of these doesn't give me the keybindings for free. – s73v3r Jan 27 at 23:37 I believe you can bind a KeyBinding to a command in your viewmodel, but to be honest I've only ever used DelegateCommand, so I can't give you a more complete example. – emddudley Jan 28 at 13:48.

If you're doing MVVM with WPF, I would strongly recommend looking at a framework to help you out, such as: Prism (provides its own DelegateCommand) MVVM Light Toolkit (provides its own RelayCommand) Caliburn. Micro (my favourite, provides Actions).

One way is to use an attached property to allow your ViewModel to define CommandBindings on the view. Check my blog post for details: CommandBindings with MVVM.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions