#440 – How Alignment Properties Behave in a WrapPanel
November 30, 2011 2 Comments
The alignment properties, when specified for children of a WrapPanel, dictate the alignment within the current row (if Orientation is Horizontal) or column (if Orientation is Vertical).
For example, the VerticalAlignment properties of controls in a WrapPanel whose Orientation is Horizontal indicate the alignment of the control with respect to the other controls within the same row.
In the example below, the William II label is set artificially high, which then dictates the height of a row that it appears in. Other controls on that same row will then align themselves relative to this height.
<WrapPanel Orientation="Horizontal"> <Label Background="AliceBlue" Content="William I" VerticalAlignment="Center"/> <Label Background="AntiqueWhite" Content="William II" VerticalAlignment="Center" Height="60"/> <Label Background="AliceBlue" Content="Henry I" VerticalAlignment="Bottom"/> <Label Background="AntiqueWhite" Content="Stephen" VerticalAlignment="Top"/> <Label Background="AliceBlue" Content="Matilda" VerticalAlignment="Stretch"/> <Label Background="AntiqueWhite" Content="Henry II" VerticalAlignment="Center"/> <Label Background="AliceBlue" Content="Richard I" VerticalAlignment="Center"/> <Label Background="AntiqueWhite" Content="John" VerticalAlignment="Center"/> </WrapPanel>
Pingback: Dew Drop – December 1, 2011 | Alvin Ashcraft's Morning Dew
Pingback: #442 – WrapPanel Child Elements Can Be Clipped « 2,000 Things You Should Know About WPF