DockPanel.Dock Attached Property
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Gets or sets a value that indicates the position of a child element within a parent DockPanel.
Namespace: System.Windows.Controls
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
<object DockPanel.Dock="Dock" .../>
Property Value
Type: System.Windows.Controls.DockThe position of a child element that is inside a DockPanel. The default value is Left.
If you set the LastChildFill property to true, which is the default setting, the last child element of a DockPanel always fills the remaining space, regardless of any other dock value that you set on the last child element. To.dock a child element in another direction, you must set the LastChildFill property to false and must also specify an explicit dock direction on the last child element.
Note: The position of child elements of a DockPanel on the screen is determined by the Dock property of the respective child elements and the relative order of those child elements under the DockPanel. Therefore, a set of child elements with the same Dock property values can be positioned differently on the screen depending on the order of these children under the DockPanel. Child ordering effects positioning because the DockPanel iterates through its child elements in order, setting the position of each element depending on remaining space.
The following example shows how to set the Dock attached property by using Extensible Application Markup Language (XAML).
WindowTitle = "DockPanel Sample" 'Create a DockPanel as the root Panel Dim myDockPanel As New DockPanel() myDockPanel.LastChildFill = True ' Define the child content Dim myBorder1 As New Border() myBorder1.Height = 25 myBorder1.Background = Brushes.SkyBlue myBorder1.BorderBrush = Brushes.Black myBorder1.BorderThickness = New Thickness(1) DockPanel.SetDock(myBorder1, Dock.Top) Dim myTextBlock1 As New TextBlock() myTextBlock1.Foreground = Brushes.Black myTextBlock1.Text = "Dock = Top" myBorder1.Child = myTextBlock1 Dim myBorder2 As New Border() myBorder2.Height = 25 myBorder2.Background = Brushes.SkyBlue myBorder2.BorderBrush = Brushes.Black myBorder2.BorderThickness = New Thickness(1) DockPanel.SetDock(myBorder2, Dock.Top) Dim myTextBlock2 As New TextBlock() myTextBlock2.Foreground = Brushes.Black myTextBlock2.Text = "Dock = Top" myBorder2.Child = myTextBlock2 Dim myBorder3 As New Border() myBorder3.Height = 25 myBorder3.Background = Brushes.LemonChiffon myBorder3.BorderBrush = Brushes.Black myBorder3.BorderThickness = New Thickness(1) DockPanel.SetDock(myBorder3, Dock.Bottom) Dim myTextBlock3 As New TextBlock() myTextBlock3.Foreground = Brushes.Black myTextBlock3.Text = "Dock = Bottom" myBorder3.Child = myTextBlock3 Dim myBorder4 As New Border() myBorder4.Width = 200 myBorder4.Background = Brushes.PaleGreen myBorder4.BorderBrush = Brushes.Black myBorder4.BorderThickness = New Thickness(1) DockPanel.SetDock(myBorder4, Dock.Left) Dim myTextBlock4 As New TextBlock() myTextBlock4.Foreground = Brushes.Black myTextBlock4.Text = "Dock = Left" myBorder4.Child = myTextBlock4 Dim myBorder5 As New Border() myBorder5.Background = Brushes.White myBorder5.BorderBrush = Brushes.Black myBorder5.BorderThickness = New Thickness(1) Dim myTextBlock5 As New TextBlock() myTextBlock5.Foreground = Brushes.Black myTextBlock5.Text = "This content will Fill the remaining space" myBorder5.Child = myTextBlock5 ' Add child elements to the DockPanel Children collection myDockPanel.Children.Add(myBorder1) myDockPanel.Children.Add(myBorder2) myDockPanel.Children.Add(myBorder3) myDockPanel.Children.Add(myBorder4) myDockPanel.Children.Add(myBorder5) Me.Content = myDockPanel
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" WindowTitle="DockPanel Sample"> <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> </Page>
Windows 8 Consumer Preview, Windows Server 8 Beta, Windows 7, Windows Server 2008 SP2, Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.