I am looking at seperating Views from their respecting ViewModels without using any code behind. On obstacle in that endevour is the commanding framework. Currently, I am using the static approach:
- That is, I have a static class MainCommands containing all static command properties that my application supports
- In the constructor of each dialog I am binding to the respective command property to the corresponding method, like so:
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.New, (s, e) => this.New_CommandExecuted(s, e), (s, e) => this.CanExecute_IfNoBatchRuns(s, e)));
Now, I noticed that this can only be done in the code behind because the this.CommandBindings bit is otherwsie not available(?).
I have also looked at other options such as the cool RelayCommand class that originated from Josh Smith's work. But with that class I am not sure how to seperate View and ViewModel without using codebehind. Plus, I need a solution that supports Short-Keys and InputGetsures when using a command in a GUI items that supports it (eg.: MenuItem).
What is the current method to go about this? Are their any samples I could look at? Here is a summary list of the requirements I am after:
- Seperate View and ViewModel without using code behind and using commands to expose ViewModel program logic functionality to the view
- Support short keys and input gestures in GUI items such as the MenuItem like with the RoutedUICommand