#446 – Default Docking for DockPanel Children

You normally specify a value for the DockPanel.Dock attached property for all children of a DockPanel, indicating which side the element should be docked to.  However, if you don’t specify a value for the Dock property, the child element will be docked to the Left, by default.

    <DockPanel LastChildFill="False">
        <ListBox ItemsSource="{Binding MovieList}"/>
        <Label Content="1 - Label at Top" DockPanel.Dock="Top" Background="Bisque"/>
        <Label Content="2 - Label at Left" DockPanel.Dock="Left" Background="BurlyWood"/>
        <Label Content="3 - Last Label" DockPanel.Dock="Top" Background="Cornsilk"/>
    </DockPanel>


Because the DockPanel container docks elements in the order that they appear in the XAML, if we change the order of the elements, the ListBox will still default to a Dock value of Left, but will dock within the remaining space.

    <DockPanel LastChildFill="False">
        <Label Content="1 - Label at Top" DockPanel.Dock="Top" Background="Bisque"/>
        <ListBox ItemsSource="{Binding MovieList}"/>
        <Label Content="2 - Label at Left" DockPanel.Dock="Left" Background="BurlyWood"/>
        <Label Content="3 - Last Label" DockPanel.Dock="Top" Background="Cornsilk"/>
    </DockPanel>

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: