WrapPanel Class
[Note: This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]
Positions child elements sequentially from left to right or top to bottom. When elements extend beyond the panel edge, elements are positioned in the next row or column.
Assembly: System.Windows.Controls (in System.Windows.Controls.dll)
WrapPanel is one of the Panel controls that enable layout. WrapPanel is useful when you want to arrange elements in a vertical or horizontal list and have elements automatically wrap to the next row or column when the height or width limit of the panel is reached. The default value for the Orientation property is Horizontal, which means elements are added from left to right, in rows. If Orientation is set to Vertical, elements are added from top to bottom in columns.
The following illustration shows an example of a WrapPanel control that displays images in a horizontal orientation. Images that extend beyond the edge are wrapped to the next line.
The following table summarizes the other available layout containers provided by Silverlight.
|
Panel name |
Description |
|---|---|
|
Defines an area that you can explicitly position child elements. |
|
|
Defines a layout control that enables you to arrange child elements around the edges of the panel. |
|
|
Defines a flexible grid area consisting of columns and rows. |
|
|
Arranges child elements into a single line that can be oriented horizontally or vertically. |
The following example shows a WrapPanel that contains several button controls. When you click the first button, you can toggle the orientation.
private void toggleButton_Click(object sender, RoutedEventArgs e) { Button toggleButton = sender as Button; WrapPanel parentPanel = toggleButton.Parent as WrapPanel; if (parentPanel != null) { if (parentPanel.Orientation == Orientation.Horizontal) parentPanel.Orientation = Orientation.Vertical; else parentPanel.Orientation = Orientation.Horizontal; } }
<controls:WrapPanel Orientation="Vertical" x:Name="buttonWrapPanel"> <Button x:Name="toggleButton" Click="toggleButton_Click" Width="Auto" Content="Click to toggle orientation" /> <Button Content="Button 2"/> <Button Content="Button 3"/> <Button Content="Button 4"/> <Button Content="Button 5"/> <Button Content="Button 6"/> <Button Content="Button 7"/> <Button Content="Button 8"/> <Button Content="Button 9"/> <Button Content="Button 10"/> <Button Content="Button 11"/> <Button Content="Button 12"/> <Button Content="Button 13"/> <Button Content="Button 14"/> </controls:WrapPanel >
System.Windows.DependencyObject
System.Windows.UIElement
System.Windows.FrameworkElement
System.Windows.Controls.Panel
System.Windows.Controls.WrapPanel
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.