This topic has not yet been rated - Rate this topic

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.

Namespace:  System.Windows.Controls
Assembly:  System.Windows.Controls (in System.Windows.Controls.dll)
public class WrapPanel : Panel
<controls:WrapPanel .../>

XAML Values

controls:

A prefix that is defined to map the XML namespace for the System.Windows.Controls assembly and the System.Windows.Controls CLR namespace.

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.

WrapPanel control

The following table summarizes the other available layout containers provided by Silverlight.

Panel name

Description

Canvas

Defines an area that you can explicitly position child elements.

DockPanel

Defines a layout control that enables you to arrange child elements around the edges of the panel.

Grid

Defines a flexible grid area consisting of columns and rows.

StackPanel

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 >


Run this sample

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)