Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a StackPanel and DockPanel in WPF?

What can a DockPanel do that a StackPanel cannot? If anyone has an image of something that can be achieved with a StackPanel, but not a DockPanel, than that would be great.

like image 764
Casebash Avatar asked Dec 01 '10 03:12

Casebash


People also ask

What is DockPanel in WPF?

DockPanel defines an area to arrange child elements relative to each other, either horizontally or vertically. With DockPanel you can easily dock child elements to top, bottom, right, left and center using the Dock property.

What is a StackPanel?

StackPanel is a layout panel that arranges child elements into a single line that can be oriented horizontally or vertically. By default, StackPanel stacks items vertically from top to bottom in the order they are declared. You can set the Orientation property to Horizontal to stack items from left to right.

What is Contentcontrol WPF?

Content Control is a base class that provides standardised functionality to WPF Controls. The Content Control class represents controls that can include a single item of content. This content is commonly plain text or a child control. Content Control is a subclass of the Control class in WPF.

Is WPF platform independent technology?

WPF however is DPI independent. So if you have two monitors with different DPI settings, Hydrology Studio automatically adjusts itself to the hardware its running on. It's built on top of DirectX, (commonly used in high-tech computer games) which can take advantage of new graphics cards as they come out.


1 Answers

Stack Panel: The StackPanel, as the name implies, arranges content either horizontally or vertically. Vertical is the default, but this can be changed using the Orientation property. Content is automatically stretched based on the orientation (see screenshot below), and this can be controlled by changing the HorizontalAlignment or VerticalAlignment properties.

StackPanel example screenshot

Dock Panel: The DockPanel is used to anchor elements to the edges of the container, and is a good choice to set up the overall structure of the application UI. Elements are docked using the DockPanel.Dock attached property. The order that elements are docked determines the layout.

DockPanel example screenshot

like image 158
Dhaust Avatar answered Sep 25 '22 17:09

Dhaust