Keyboard shortcuts in WPF MVVM? -
i have wpf application follow mvvm pattern. need implement keyboard shortcuts. these shortcut have contol webbrowser control behaviour. defined first custom command , added view's inputbindings. there more commands , have invoke scripts on browser:
mainwindow.xaml.cs:
... commandbinding cb = new commandbinding(remotecontrolcommands.testcommand, mycommandexecuted, mycommandcanexecute); this.commandbindings.add(cb); keygesture kg = new keygesture(key.q, modifierkeys.control); inputbinding ib = new inputbinding(remotecontrolcommands.testcommand, kg); this.inputbindings.add(ib); } private void mycommandexecuted(object sender, executedroutedeventargs e) { webbrowser.invokescript("foo", "hello world!"); } private void mycommandcanexecute(object sender, canexecuteroutedeventargs e) { e.canexecute = true; }
my question how fit mvvm patern? mvvm new concept me understand how bind view's command view model , there execute methods or change properties. need in case execute method on control in view. best place shortcut handling in scenario?
<window.inputbindings> <keybinding command="{binding mycommand, source=viewmodel...}" commandparameter="{binding,elementname=browsercontrol,mode=self}" gesture="ctrl+r" /> </window.inputbindings>
you can bind command property view model's command.
Comments
Post a Comment