1
Answer

TextBox RaiseEvent KeyDownEvent does not work

Rn

Rn

13y
8.2k
1
Trying to raiseEvent to textBox - but i don't see the key value in the textBox text. I can see that the textbox event "OnKeyDownEvent" is stopping in breakpoints - but i don't understand why the text of the KeyEventArgs ( Key.D0 ) is not insert into the textbox text.

The code:


 if( TextBoxInFocus != null ) 
{
KeyEventArgs k =
new
KeyEventArgs( Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, System.Environment.ProcessorCount, Key.D0 );
//
KeyEventArgs k = new KeyEventArgs( Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource, 0, Key.D0 );
k.RoutedEvent = UIElement.KeyDownEvent;
TextBoxInFocus.RaiseEvent( k );
k.RoutedEvent = UIElement.KeyUpEvent;
TextBoxInFocus.RaiseEvent( k );



}
Answers (1)