Search code examples
wpflistviewdockpanel

wpf DockPanel issue


I have DockPanel with ListView and StackPanel:

<DockPanel Margin="5" LastChildFill="True">
    <ListView Margin="5" ItemsSource="{Binding Source={StaticResource taxGroupSource}}" DockPanel.Dock="Top" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Last Name" DisplayMemberBinding="{Binding SerialNumber}" />
                <GridViewColumn Header="First Name" DisplayMemberBinding="{Binding Name}" />
            </GridView>
        </ListView.View>
    </ListView>
    <StackPanel DockPanel.Dock="Bottom" Style="{StaticResource buttonPanel}">
        <Button Content="Close" Click="CloseClick"/>
    </StackPanel>
</DockPanel>

When GridView have great rows count, ListView overlaps bottom StackPanel. Why?


Solution

  • I believe the issue is your LastChildFill on the DockPanel iteself. As explained by MSDN, LastChildFill makes it so that your StackPanel takes the remaining space in the DockPanel, even though you have set it to dock at the bottom. Try removing the attribute and seeing if that helps.

    Edit: Removing the attribute alone does not do it. I got the expected behavior by swapping the ListView and StackPanel, but that changes the tab order (although here it is only between two items so setting the focus to the ListView makes it look right).

    Alternately, can you use a grid with two rows--the ListView in the first row with a height of "*" and the StackPanel in the second with a height of "Auto"? Or is this a simplification of a more complex layout where that would not work?