WPF: Is a ListBox or Panel responsible for mouse navigation?

I have a custom ListBox that uses a custom bar like ItemsHost. I want to control the mouse wheel input, so turning the wheel changes one selected item.

I believe the best way to do this is to handle the OnPreviewMouseWheel event (although this only has what I want as it does not provide horizontal wheel data).

Now the big question is: is there any best practice where to handle OnPreviewMouseWheel? In the ListBox (which by default has no idea about the location of the Panel children) or in the Panel (which by default has no idea about the IsSelected property for the children)?

+3
source share
2 answers

I think you should make it out ListBox. ListBoxinherits from Selector , which handles everything related to the selection.

The wheel selection behavior can be applied with any type Panel(it might even be a good idea to implement it using the standard one ListBox), and you can use Panelit somewhere outside ListBoxwhere the logic of choice makes no sense.

0
source

This should be done from a ListBox, since only he knows which item is currently selected. The panel does not want or does not want to know whether it is selected or not.

, .

:
- (, ListBoxSelector) MouseWheelChangesSelection (true/false).
- PropertyNotifyChangedEvent PreviewMouseWheel/MouseWheel.

:
- ;
- prev/next

0

Source: https://habr.com/ru/post/1704879/


All Articles