I have a ListView control. I want to make it stretch to fill the entire length of a column. To achieve this, I set the ColumnDefinition to "*". I set the ListView‘s VerticalAlignment property to Stretch, both for the ListView and for its containing elements.
Currently, the ListView will only increase in size when data is shown inside of it.
How do I make the ListView stretch to the size of the column no matter what data is shown inside it?
Here is a sample version of my XAML file. It shows that the VerticalAllignment is set to stretch on the ListView and all of the containing elements:
<Grid>
<TabControl>
<TabItem Header="Main"
Margin="1,-1,-2,1">
<Grid Background="#FFE5E5E5" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Border BorderBrush="Black"
BorderThickness=".5"
Padding="4"
Grid.Column="0"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch">
<StackPanel Orientation="Vertical"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch" >
<ListView x:Name="FilesDisplayed"
ItemsSource="{Binding AllFilePaths}"
SelectionChanged="FilesDisplayed_SelectionChanged"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Visible"/>
>Solution :
Avoid using StackPanel when you want inner elements to fill the outer space. Replace it with Grid and use Grid.ColumnDefinitions or Grid.RowDefinitions to adjust the location.