Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
ListView height inside of a StackPanel - problem...
Message
From
19/06/2008 13:28:14
 
 
To
18/06/2008 16:57:39
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Miscellaneous
Thread ID:
01325263
Message ID:
01325498
Views:
18
>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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform