Silverlight Feeds - All your Silverlight feeds in one place.

Sponsors

Saturday, November 07, 2009

WPF4: KeyBinding e MouseBinding improvements

by Corrado Cavalli via Corrado's BLogs on 11/7/2009 10:28:24 AM

Usare delle combinazioni di tasti oppure il mouse come shortcut per alcune funzionalità tipo Apri, Stampa, Salva etc è un requisito abbastanza comune, peccato che gestire questo aspetto utilizzando il pattern Model-View-ViewModel non sia proprio banale a causa di una piccola limitazione: la proprietà Command dell’oggetto KeyBinding non è una dependency property.
Il workaround ovviamente esiste, è però un peccato che si debba reinventare la ruota per realizzare banalità del genere.
Con WPF4 finalmente la proprietà Command di MouseBinding e  KeyBinding diventano delle dependency properties questo significa che è possibile mappare delle gestures verso dei comandi in questo modo:

   1: <Window.InputBindings>
   2:         <KeyBinding Command="{Binding ExitCommand}"
   3:                     Key="{Binding ExitCommand.GestureKey}"
   4:                     Modifiers="{Binding ExitCommand.GestureModifier}" />
   5:         <MouseBinding Command="{Binding ExitCommand}"
   6:                       MouseAction="{Binding ExitCommand.MouseGesture}" />
   7:     </Window.InputBindings>

Notate inoltre come Key,Modifiers e MouseAction siano anch’esse delle dependency properties percui è possibile definirle direttamente all’interno del Command esposto dal ViewModel

Technorati Tags: ,,
email it!bookmark it!digg it!

Original Post: WPF4: KeyBinding e MouseBinding improvements

Subscribe

New Feed

Product Spotlight

Recently Updated Sources

Legal Note

The content of the postings is owned by the respective author. Silverlight Feeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on Silverlight Feeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.

Advertise with us