Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Arrow keys(left,right) down is not captured from PreviewKeyDown event within WPF Attach behaviour

$
0
0

Hi,

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,
            DependencyPropertyChangedEventArgs e)
        {
            if (d is UIElement)
            {
                UIElement element = d as UIElement;
                
                if (element != null)
                {
                    if ((bool)e.NewValue)
                    {
                        element.PreviewKeyDown -= OnPreviewKeysDown;
                        element.PreviewKeyDown += OnPreviewKeysDown;

                        element.KeyUp -= OnKeysUp;
                        element.KeyUp += OnKeysUp;

                        element.GotFocus-= OnGotFocus;
                        element.GotFocus+= OnGotFocus;
                     
                    }
                }
            }
        }


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>