c# - WPF correct way to set a bool while a key is pressed -
I need to set WPF a boolean variable (and some other actions besides this), while a key is pressed To wit. Pressed to set on key, and the key is released to reset. Something that I can do only by event handlers:
this.KeyDown + = New KeyEventHandler (MyModuleView_KeyDown); This.KeyUp + = New KeyEventHandler (MyModuleView_KeyUp); Bull MyFlag = Incorrect; Zero MyModuleView_KeyUp (Object Sender, KeyEventArgs E) {if (e.Key == System.Windows.Input.Key.Space) {MyFlag = false; ...}} Zero MyModuleView_KeyDown (Object Sender, KeyEventArgs e) {if (e.Key == System.Windows.Input.Key.Space) {MyFlag = true; ...}} But I suspect the WPF can be done more accurately.
I am trying to use a command approach, but the way I do it can set a variable on on fact when pressing only one key, but While the key is not pressed. Private Static RoutineIiCom mymode; Input gesture clip input = new input stewardess (); Inputs.Add (new keyGesture (key Space, "Space")); MyMode = New Routad UICOM ("Mimeode", "Mimeode", Typef (Interface Commands), Input); Public static Routeyed Ukmand Mimod {receive {mymode return}; }} ... Private Zero MyModeCommand_Executed (Object Sender, ExecutedRoutedEventArgs e) {MyFlag = true; ...} How to accurately track the key position for a key to turn on (for example the cursor selection mode) while key is pressed?
Orders here will not help you, the right way to approach your view is to get the code- Do not want to be behind - you can create custom enclosed properties, which will be responsible for the stars of events.
Comments
Post a Comment