Reputation: 57
The behaviour of a listbox when its width or height is set to auto is to not produce any scrollbars as it will attempt to endlessly grow within its container.
Is there any way to have a Listbox that will resize to the space available within the container it resides within while still displaying scrollbars for content that would be beyond these boundaries?
My application is not of a fixed size so I can't rely on setting fixed values for the Listbox or its container.
Upvotes: 2
Views: 1372
Reputation: 184506
If your ListBox grows beyond the borders, the container is set up the wrong way (e.g. StackPanels will not confine contents in its orientation direction), other than that you can ensure the visibility of the scroll-bars like this:
<ListBox ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible">
...
</ListBox>
By default the scrollbars are shown automatically as soon as the content would no longer fit the container, if the scrollbars do not show up even though the content exceeds the bound your container is at fault as mentioned before.
Upvotes: 2