0
votes

Disabling the SelectionChanged event of WPF combobox on navigating through arrow up and down key.

I think it is repetitive questions but even am asking same question. Because i didn't get answer from whatever post already posted.

I wanted to disable SelectionChanged event on arrows up and down key. I have two events PreviewKeyDown and PreviewKeyUp for combobox in which i have wrote "e.handled = true". This code is worked for all others key but not for up and down arrow key. After pressing the arrow key's SelectionChanged event get triggered.

Help would be appreciated.

1

1 Answers

0
votes

I tried with the following code and its work fine.

protected override void OnPreviewKeyDown(KeyEventArgs e)
            {
                if (IsReadOnly)
                {
                    if (e.Key == Key.Down || e.Key == Key.Up)
                    {
                        e.Handled = true;
                        return;
                    }
                }

                base.OnPreviewKeyDown(e);
            }