Quantcast
Channel: Remove additional vertical whitespace from WPF - Stack Overflow
Viewing all articles
Browse latest Browse all 7

Answer by Joe White for Remove additional vertical whitespace from WPF

$
0
0

By default, controls will expand to fill all the space its container will give it. That's what you're seeing, and it's expected, since you didn't tell it to do anything else (i.e., you didn't set any alignment properties on the ListBox).

If you'd rather have the ListBox take up only as much height as necessary to show its items, then set its VerticalAlignment property to something other than the default value of Stretch. For example:

<ListBox Name="personListBoxTest"         VerticalAlignment="Top"         ...

Or you could use Bottom or Center if you prefer -- whatever makes the most sense for your layout.

Assuming you use Top, then if the listbox only has enough items to fill half of the space given by the ListBox's parent, then the whole ListBox will only take up that much space, and the remainder of the parent will be empty. But if there get to be so many ListBox items (or the parent gets so small) that the items won't all fit, the ListBox will fill all the space and show a scrollbar, just like you'd want it to.


Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>