Warning: Parameter 2 to wp_hide_post_Public::query_posts_join() expected to be a reference, value given in /kunden/359776_36129/webseiten/blog/wp-includes/class-wp-hook.php on line 286

1: goto 1;

CommandBinding with dynamic Shortcut Support


In MVVM you normally don´t use Click-Event like in WinForms, Java Swing or other traditional GUI-Framework. On of the aims of MVVM is to reduce the binding between presentation and program logic. The way you do bind Actions to a button (or other control) is by an implementation of the ICommand interface, that is hold by the ViewModel. The View binds to this property to create the link between implementation and triggering of the command. A common implementation is the RelayCommand class, which supports a basic functionality of this.

The implementation

In my applications I improved this by adding a flexable support for shortcut-bindings, which allows me to (re)bind the Menu- and Button-Command shortcuts at runtime. This is used to allow the user to change the default shortcuts in the configuration window.

The ViewModel implementation is quite the same like the RelayCommand Class:

Binding in the View works like this:

Changing the shortcut at runtime is really simple: just assign a different key and/or modifier to the object hold by the NewFileCommand-Property. Due to the INotifyPropertyChanged, the View gets informed about the change.

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)