July 17th, 2013, 11:57 PM
Arrow keys(left,right) down is not captured from PreviewKeyDown event within WPF
I was just trying to capture left arrow and right arrow key movement over the text in wpf textbox. I implemented a wpf attached behaviour for the textbox and bound PreviewKeyDown event.
Although, it's capturing all other keys(including Enter,backspace, shift) but it's not capturing the arrow keys.
Can anyone tell me why it's like that?
Thanks in advance.
Below is the function where I am binding it..
private static void OnHandleKeysUp(DependencyObject d,
if (d is UIElement)
UIElement element = d as UIElement;
if (element != null)
element.PreviewKeyDown -= OnPreviewKeysDown;
element.PreviewKeyDown += OnPreviewKeysDown;
element.KeyUp -= OnKeysUp;
element.KeyUp += OnKeysUp;
Click Here to Expand Forum to Full Width