We have a form that contains various elements and a datagrid. When the list box is contained in a scroll viewer, all is well when we increase the size of the window. When the window size is decreased the list box remains the same height and the vertical scrollbar becomes active. If you get rid of the height binding on the list box, the list box goes to its maximum required height. If we dont have a list box at all the border behaves as we want.
We can simulate our problem using the following 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="150"
Width="525">
<Grid
Margin="10">
<ScrollViewer>
<Grid>
<Grid.RowDefinitions>
<RowDefinition
Height="*" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<Border
x:Name="border"
MinHeight="40" />
<ListBox
Height="{Binding ElementName=border, Path=ActualHeight}">
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 1</ListBoxItem>
</ListBox>
<ToolBar
Grid.Row="1">
<Button
Content="Add" />
</ToolBar>
</Grid>
</ScrollViewer>
</Grid>
</Window>
How do we get the ListBox to resize the same way the border does when there is no ListBox?