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

Answer by Dave Hanson for Remove additional vertical whitespace from WPF

$
0
0

You need to make the container that contains the ListBox to have a height of AUTO

ListBox1 is in a row of height AUTO

ListBox2 is in a row span of height *

This'll allow you to have the correct height on the listbox as the size of the values in the container up until the max height of the container that is holding it... kind of confusing but hope it makes sense.

Hope that helps!

See this sample code

<Window x:Class="WpfApplication1.MainWindow"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    Title="MainWindow" Height="350" Width="525"><Grid><Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition Width="*"/></Grid.ColumnDefinitions><Grid.RowDefinitions><RowDefinition Height="auto"/><RowDefinition Height="*"/></Grid.RowDefinitions><ListBox Grid.Column="0" Grid.Row="0" Background="blue"><ListBoxItem>I'm an item in listbox1</ListBoxItem><ListBoxItem>I'm an item in listbox1</ListBoxItem><ListBoxItem>I'm an item in listbox1</ListBoxItem><ListBoxItem>I'm an item in listbox1</ListBoxItem><ListBoxItem>I'm an item in listbox1</ListBoxItem><ListBoxItem>I'm an item in listbox1</ListBoxItem></ListBox><ListBox Grid.Column="1" Grid.RowSpan="2" Grid.Row="0"  Background="red"><ListBoxItem>I'm an item in listbox2</ListBoxItem><ListBoxItem>I'm an item in listbox2</ListBoxItem><ListBoxItem>I'm an item in listbox2</ListBoxItem><ListBoxItem>I'm an item in listbox2</ListBoxItem><ListBoxItem>I'm an item in listbox2</ListBoxItem><ListBoxItem>I'm an item in listbox2</ListBoxItem><ListBoxItem>I'm an item in listbox2</ListBoxItem></ListBox></Grid>


Viewing all articles
Browse latest Browse all 7

Trending Articles



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