Partager via


Using the DockPanel layout panel

JJ170224.bf9c77b1-ba7a-4f3b-8380-d05728d208d1(fr-fr,VS.110).png

A DockPanel layout panel in a Windows Presentation Foundation (WPF) project provides a layout area within which you can arrange child objects around the edge of the screen based on compass direction: North, South, East, and West. The DockPanel was historically used for root layout in other forms packages, because it allows panels to be docked around the edge of the screen.

When you add child objects to a DockPanel, the objects are docked to the left part of the panel by default. The last child object that you add can fill the remaining space in the panel if the LastChildFill property for that object is set to True. By default, this property is set to False. When objects fill up the panel, they are then clipped or hidden by the parent layout container.

If you drag a child object of a DockPanel on the artboard, notice that a large four-way pointer shows the directions that you can dock the object (see image below). You can use this four-way pointer as an alternative way to change dock orientation. Simply drag the object over the direction arrow that you want. Notice that the direction arrow that you select becomes highlighted, to indicate that you can drop the object to dock it in that direction.

Add a DockPanel to a document by selecting DockPanel JJ170224.db9f1ff5-6bca-441d-b289-c6781a478a5b(fr-fr,VS.110).png from the Assets panel JJ170224.0d8b8d29-1af9-418f-8741-be3097d76eab(fr-fr,VS.110).png or from the layout container button in the Tools panel, and then dragging with the pointer on the artboard. The following XAML code is added to your project:

<Grid x:Name="LayoutRoot">
   <DockPanel HorizontalAlignment="Left" Height="100" LastChildFill="False" VerticalAlignment="Top" Width="100"/>
</Grid>

For more about how to work with DockPanel objects, see the related topics, Change the docking order and Change the dock orientation.

JJ170224.72d46b58-9a49-4dd5-8af7-6843c0440226(fr-fr,VS.110).png