Search code examples
wpfscrollitemscontrolscrollviewer

WPF: Srollviewer not working in Items control


I have a itemscontrol under scrollviewer. and under this items control I have another Usercontrol with items control under scroll viewer. something like this:

scrollviewer
itemscontrol
....
/itemscontrol
/scrollviewer

under the above itemscontrol there is a usercontrol having:

scrollviewer
itemscontrol
....
/itemscontrol
/scrollviewer

When the mouse is pointed on the first scrollview or itemscontrol, then scrolling works, but as the mouse comes on the second items control, the scrolling doesn't work.

Can anyone help me out and tell me where i'm wrong?

Note: removed the tags <> due to HTML not showing.


Solution

  • Check out WPF Tips'n'Tricks #6: Preventing ScrollViewer from handling the mouse wheel.

    Not only does ScrollViewer handles the mouse scrolling even when no more scrolling is needed, but it also does so when there's nothing to scroll, or worse when it is told not to scroll!

    How can we change the ScrollViewer to behave more like it's supposed to? The most direct approach is to leverage the tunneling and bubbling events and use them against the buggy control.

    The idea is that if the PreviewMouseWheel is handled, WPF will not generate the MouseWheel event, and in turn the ScrollViewer will not scroll.

    The article includes the code for a full solution to the problem.