Changing the FlowDirection property of a StackPanel changes how it lays out elements when its Orientation is set to Horizontal.

When Orientation is Horizontal and FlowDirection is LeftToRight (the default), each label’s width is set to fit its content. The label’s height is stretched to fill the container. Labels are arranged left to right.

Changing FlowDirection to RightToLeft, the labels are arranged from right to left.

If Orientation is Vertical and FlowDirection is LeftToRight, the labels’ width now sizes to fit the container and their height is set to match the content. The labels are arranged from top to bottom in the StackPanel.

Changing FlowDirection to RightToLeft when the orientation is Vertical does not change how the labels are arranged. They are still ordered from top to bottom in the StackPanel. The content of the labels, however, is now right-aligned, rather than left-aligned.

You’ll often want to stack a group of buttons in a GUI, vertically or horizontally. You’d typically use a StackPanel to do this.

Let’s say that you want a series of buttons stacked vertically on the right side of a window.

We can use a DockPanel as the main container and add a StackPanel docked on the right and oriented vertically. But when we do this, the StackPanel expands to fill the available space, as does each Button.

The HorizontalAlignment of the StackPanel defaults to Stretch, as do each of the buttons. We could set the HorizontalAlignment for each Button to Right, but the buttons now all size to fit their content, which is not quite what we want.

What we really want is for the HorizontalAlignment of each Button to be Stretch, but for the HorizontalAlignment of the StackPanel itself to be Right. This gives us what we want.

Every FrameworkElement has a FlowDirection property that can be either LeftToRight (the default), or RightToLeft. For panel elements that lay out a series of child elements, this property indicates in which direction the layout should be done.

The FlowDirection property is typically used for cultures where text flows from right to left, e.g. Arabic. However, you can use this property whenever a right-to-left layout would make sense.

The DockPanel layout container is most often used to dock other container controls along each edge of a window and perhaps include a control that fills the remaining space. This works well as the outermost container for a main application window.

But because you can stack multiple controls consecutively on the same side, you can use a DockPanel like a StackPanel, but stacking controls in any direction.

Docking everything to the left:

Docking everything to the right:

To the top:

Or the bottom:

You can also use various combinations, stacking a series of controls to one side and then another group of controls to another side.