Search code examples
c#wpflistboxscrollviewer

WPF ListBox Scrolling Dilemma


I ran into kind of a dilemma with WPF's scrolling behavior in a ListBox:

  • When I set ScrollViewer.VerticalScrollBarVisibility="Auto" inside the ListBox, scrolling works fine. But clicking on the last half-visible element will move the item up to bring it into view, and the items then are aligned to the top of the topmost item, not the bottom of the lowest one. This is especially annoying when double clicking, as the item will move up under the cursor, and the second click will potentially hit the next element, thus opening the wrong one.
  • Alternatively, I could put the whole ListBox inside a ScrollViewer. This way, when clicking on the last visible item, the items are nicely aligned to the bottom of this element. But this breaks scrolling using the mouse wheel, and PageDown jumps to the last item instead of one page down.

Is there a way to have ListBox scrolling just work correctly?


Solution

  • To the point one:

    Did you try to set ScrollViewer.CanContentScroll="False"?