>I have a ListView in a StackPanel and when I set the ItemSource property on the ListView it in the code-behind, the height of the ListView becomes taller that StackPanel, and it make the ListView chopped off at the bottom of the StackPanel.
>I did not hard-code the height of the ListView, but I thought the default behavior was that the last control in a StackPanel automatically fills the rest of the StackPanel height?
>
>If I hard-code a height in the XAML, it does fine, but I do not want to hard-code height.
>
>What am I missing?
>
>
It's the DockPanel that has that behavior. Use it instead of the StackPanel here. It's hard not to think of it as a toolbar layout control, but it is actually used all over the place and is just another layout control like a StackPanel.
<DockPanel>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Top" >
<TextBox x:Name="txtCustomerFilter" Width="100" Margin="5"></TextBox>
<Button x:Name="ButtonSearch" Width="50" Margin="5" >Search</Button>
</StackPanel>
<ListView Name="lv2" HorizontalContentAlignment="Stretch"
ScrollViewer.VerticalScrollBarVisibility="Visible" >
StackPanel = Fixed vertical or horizontal layout.
WrapPanel = Horizontal layout that will wrap if not enough room.
DockPanel = Allows you to specify top, bottom etc last Item fills remaining space.
Canvas = Fixed Layouts.
Grid = Row / Column Layouts.
Grid would be your other choice here: (Note the row height definitions Auto and *)
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0">
<TextBox x:Name="txtCustomerFilter" Width="100" Margin="5"></TextBox>
<Button x:Name="ButtonSearch" Width="50" Margin="5" >Search</Button>
</StackPanel>
<ListView Name="lv2" HorizontalContentAlignment="Stretch"
ScrollViewer.VerticalScrollBarVisibility="Visible"
Grid.Row="1">
Looking good BTW