Question

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?

Was it helpful?

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?

OTHER TIPS

As @DocMax said the last child fill would work ONLY if there is some space available in the dockpanel after all previous children are occupied. For ListView having large number of rows, the space is already taken up by it so stackpanel is left with no space to occupy.

I suggst you supply some MinHeight to the stackpanel.

If you don't want to use Grid, then you can solve it by adding StackPanel first and then ListView, with using LastChildFill="True".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top