Bahman_Aries
Bahman_Aries

Reputation: 4798

What is the logic behind The order of DockPanel children elements

I know the order of DockPanel children elements matters. I've read somewhere that layout of a child is determined based on the available space left after all previous children have already been positioned. So for example for this piece of code:

<DockPanel>
    <Button DockPanel.Dock="Bottom" Height="20" Content="MyButton"/>
    <DataGrid Name="dataGrid" ItemsSource="{Binding CarList.Items}"/>
</DockPanel>

I'm getting a result like picture below where my Button is docked to the bottom as expected:

enter image description here

Now if I change the order of children elements like this:

<DockPanel>
    <DataGrid Name="dataGrid" ItemsSource="{Binding CarList.Items}"/>
    <Button DockPanel.Dock="Bottom" Height="20" Content="MyButton"/>
</DockPanel>

The layout gets weired:

enter image description here

Regardless of the fact that my Button uses the available space left, shouldn't at least it gets docked to the bottom of this space?

Upvotes: 3

Views: 1544

Answers (1)

Il Vic
Il Vic

Reputation: 5666

You are not considering the DockPanel LastChildFill property. As you can read:

true if the last child element stretches to fill the remaining space; otherwise false. The default value is true.

Anyway you can find a good tutorial here.

Upvotes: 4

Related Questions