I have a WPF ListBox that typically shows 4 or 5 items. For my application that means I almost never have to display a scrollbar (there is enough space).
However, in case there are more items in the list, I need to show the vertical scroll bar, but as a result my content has less space and doesn’t look nice anymore on a “backdrop” I’ve created behind the listbox.
I like to “reserve” room in my layout for the scrollbar to appear. Is there a way to do that? (maybe having the scrollbar overlayed on the content)
Alright, found a solution.
I’ve created a new default style for the ScrollViewer by following this MSDN article. Then I’ve changed the part where the scrollbars are placed.
Original behaviour
New behaviour
Now the scrollbars are overlayed on the content so they don’t take additional space when visible. Of course the content should now reserve space for the content.