0

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!

oli.G
  • 1,300
  • 2
  • 18
  • 24
  • 3
    Just a side note to help debug: have you tried using [snoop](http://snoopwpf.codeplex.com/)? You can attach to your WPF application at runtime, viewing the states of properties, etc. But it can also show you the events tunnelling down or bubbling up the tree, and which control handles it. – DJH Dec 03 '13 at 15:40
  • Thanks for the tip, this tool looks super useful! – oli.G Dec 03 '13 at 15:54
  • And thanks to Snoop, I found out that the KeyDown event is handled by Slider's Thumb (if the key is a value-altering one) – oli.G Dec 03 '13 at 15:57
  • Have you solved your issue? Please provide your solution in form of an answer. – dev hedgehog Dec 03 '13 at 18:20
  • I may have found a way to go, but it's takes time I don't have now. I will come back to it tomorrow and I will definitely answer my question when the solutions works :) – oli.G Dec 03 '13 at 20:17

0 Answers0