Home > Tips & Tricks > How to Dock Child as FILL in WPF ?

How to Dock Child as FILL in WPF ?


 

Hi Friends…

 

This is what i found in WPF. Here is the example of how to dock the panel as Fill. There is no such things like DockStyle as Fill. But there is an indirect way to do this. Just have a look at the following code.

 

    <DockPanel LastChildFill="True">

        <Border Height="25"

                Background="SkyBlue"

                BorderBrush="Black"

                BorderThickness="1"

                DockPanel.Dock="Top">

            <TextBlock Foreground="Black">Dock = "Top"</TextBlock>

        </Border>

        <Border Height="25"

                Background="SkyBlue"

                BorderBrush="Black"

                BorderThickness="1"

                DockPanel.Dock="Top">

            <TextBlock Foreground="Black">Dock = "Top"</TextBlock>

        </Border>

        <Border Height="25"

                Background="LemonChiffon"

                BorderBrush="Black"

                BorderThickness="1"

                DockPanel.Dock="Bottom">

            <TextBlock Foreground="Black">Dock = "Bottom"</TextBlock>

        </Border>

        <Border Width="200"

                Background="PaleGreen"

                BorderBrush="Black"

                BorderThickness="1"

                DockPanel.Dock="Left">

            <TextBlock Foreground="Black">Dock = "Left"</TextBlock>

        </Border>

        <Border Background="White"

                BorderBrush="Black"

                BorderThickness="1">

            <TextBlock Foreground="Black">This content will "Fill" the remaining space</TextBlock>

        </Border>

    </DockPanel>

 

In the above code you will find property called LastChildFill="True" of the DockPanel. Whatever the last element of the dockpanel will have DockStyle as Fill by default. Just try this out.

Categories: Tips & Tricks
  1. No comments yet.
  1. No trackbacks yet.

Leave a comment