Handle and bubble up WPF Slider's KeyDown event, when value-altering key is pressed

572 views Asked by At

I have a ListBox in which the ItemTemplate contains a Slider control. When we focus a Slider and press the keys up and down, it changes the value just like when pressing left and right. I would like to override this behavior - I want to cancel the value change and let the event bubble up to the parent ListBox, which will make it select the previous / next item.

I was going to undo the value change in Slider's KeyDown handler, and let the event bubble up (by making sure that Handled = false) , hoping that an unhandled KeyDown event originating from the child Slider will make the ListBox act as usual and change the SelectedItem. I'm not sure if that's how the ListBox would behave, but I've encountered problems way before that point:

  1. the KeyDown event doesn't seem to be bubbling up from the slider
  2. not even attaching a KeyDown handler to the Slider itself works - unless I press some other key; pressing the value-altering keys doesn't seem to fire the KeyDown event at all, only a ValueChanged event

How I should go about this problem? Thanks!

0

There are 0 answers