Wrap​Grid Wrap​Grid Wrap​Grid Class

Definition

Positions child elements sequentially from left to right or top to bottom. When elements extend beyond the container edge, elements are positioned in the next row or column. Can only be used to display items in an ItemsControl.

Note

Starting in Windows 8.1, we recommend that you use ItemsWrapGrid instead of WrapGrid.

public sealed class WrapGrid : OrientedVirtualizingPanel, IWrapGridpublic sealed class WrapGrid : OrientedVirtualizingPanel, IWrapGridPublic NotInheritable Class WrapGrid Inherits OrientedVirtualizingPanel Implements IWrapGrid
<WrapGrid ...>
  oneOrMoreUIElements
</WrapGrid>
Inheritance
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Inherited Members

Inherited properties

Inherited events

Inherited methods

Windows.UI.Xaml.Controls.Primitives.OrientedVirtualizingPanel.GetInsertionIndexes(Windows.Foundation.Point,System.Int32,System.Int32)Windows.UI.Xaml.Controls.Primitives.OrientedVirtualizingPanel.GetInsertionIndexes(Windows.Foundation.Point,System.Int32,System.Int32)Windows.UI.Xaml.Controls.Primitives.OrientedVirtualizingPanel.GetInsertionIndexes(Windows.Foundation.Point,System.Int32,System.Int32)
Windows.UI.Xaml.Controls.Primitives.OrientedVirtualizingPanel.GetRegularSnapPoints(Windows.UI.Xaml.Controls.Orientation,Windows.UI.Xaml.Controls.Primitives.SnapPointsAlignment,System.Single)Windows.UI.Xaml.Controls.Primitives.OrientedVirtualizingPanel.GetRegularSnapPoints(Windows.UI.Xaml.Controls.Orientation,Windows.UI.Xaml.Controls.Primitives.SnapPointsAlignment,System.Single)Windows.UI.Xaml.Controls.Primitives.OrientedVirtualizingPanel.GetRegularSnapPoints(Windows.UI.Xaml.Controls.Orientation,Windows.UI.Xaml.Controls.Primitives.SnapPointsAlignment,System.Single)

Remarks

Note

Starting in Windows 8.1, ItemsWrapGrid is used as the default ItemsPanel for GridView. If you modify the ItemsPanel, we recommend you use ItemsStackPanel or ItemsWrapGrid instead of VirtualizingStackPanel or WrapGrid.

WrapGrid can only be used to display items in an ItemsControl.

The content of a WrapGrid is virtualized. This can improve performance when you work with large data sets. For more info, see Optimize ListView and GridView.

In a WrapGrid, elements are arranged in rows or columns that automatically wrap to a new row or column when the MaximumRowsOrColumns value is reached. The Orientation property specifies whether the grid adds its items in rows or columns before wrapping.

When the value is Vertical, the grid adds items in columns from top to bottom, then wraps from left to right, like this:

Item 1Item 4Item 7
Item 2Item 5Item 8
Item 3Item 6Item 9

When the value is Horizontal, the grid adds items in rows from left to right, then wraps from top to bottom, like this:

Item 1Item 2Item 3
Item 4Item 5Item 6
Item 7Item 8Item 9

Windows 8 behavior

For Windows 8, items added to the items lists programmatically at run-time sometimes would start a new row in the internal grid representation, even if the item could have been added to an existing row based on the MaximumRowsOrColumns setting.

Starting with Windows 8.1, items added to items lists programmatically at run-time will fill rows in expected ways, starting a new row only when row-column limits are exceeded.

This behavior difference usually has no effect on the layout the user sees, because the items control that contains the WrapGrid is ultimately controlling the layout. But the difference can be detected if you are using coordinate-relative techniques to check the layout within the WrapGrid. For instance, you might see coordinate differences if you are calling TransformToVisual or VisualTreeHelper API, with the WrapGrid as the "relative-to" element.

If you migrate your app code from Windows 8 to Windows 8.1, and you're doing advanced layout verification with TransformToVisual or VisualTreeHelper within a WrapGrid you may want to account for this behavior change.

Apps that were compiled for Windows 8 but running on Windows 8.1 continue to use the Windows 8 behavior.

Constructors

WrapGrid() WrapGrid() WrapGrid()

Initializes a new instance of the WrapGrid class.

public WrapGrid()public WrapGrid()Public Sub New()
Attributes

Properties

HorizontalChildrenAlignment HorizontalChildrenAlignment HorizontalChildrenAlignment

Gets or sets the alignment rules by which child elements are arranged for the horizontal dimension.

public HorizontalAlignment HorizontalChildrenAlignment { get; set; }public HorizontalAlignment HorizontalChildrenAlignment { get; set; }Public ReadWrite Property HorizontalChildrenAlignment As HorizontalAlignment
<WrapGrid HorizontalChildrenAlignment="horizontalAlignmentMemberName" />
Value
HorizontalAlignment HorizontalAlignment HorizontalAlignment

A value of the enumeration. The default is Left.

Attributes

HorizontalChildrenAlignmentProperty HorizontalChildrenAlignmentProperty HorizontalChildrenAlignmentProperty

Identifies the HorizontalChildrenAlignment dependency property.

public static DependencyProperty HorizontalChildrenAlignmentProperty { get; }public static DependencyProperty HorizontalChildrenAlignmentProperty { get; }Public Static ReadOnly Property HorizontalChildrenAlignmentProperty As DependencyProperty
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the HorizontalChildrenAlignment dependency property.

Attributes

ItemHeight ItemHeight ItemHeight

Gets or sets the height of the layout area for each item that is contained in a WrapGrid.

public double ItemHeight { get; set; }public double ItemHeight { get; set; }Public ReadWrite Property ItemHeight As double
<WrapGrid ItemHeight="double" />
Value
double double double

The height of the layout area for each item that is contained in a WrapGrid. The default is Double.NaN, which results in the "Auto" layout behavior.

Attributes

Remarks

"Auto" layout and Double.NaN

The default value of ItemHeight and ItemWidth is not 0, it is Double.NaN. ItemHeight and ItemWidth support the ability to be an unset "Auto" value. Because ItemHeight and ItemWidth are Double values, Double.NaN is used as a special value to represent this "Auto" behavior. The layout system interprets the "Auto" value to generally mean that the object should be sized to the available size in layout, instead of to a specific pixel value. If you want the "Auto" behavior for an object when it is used in layout, leave ItemHeight and ItemWidth unset at their Double.NaN default value. If you have previously set values and want to reenable the "Auto" behavior with run-time code, set to Double.NaN. In XAML such as templates, you can set attribute values using the string "Auto".

Note

Visual C++ component extensions (C++/CX) doesn't have a constant for NaN, it uses a value, which appears as "-1.#IND" followed by zeros.

ItemHeightProperty ItemHeightProperty ItemHeightProperty

Identifies the ItemHeight dependency property.

public static DependencyProperty ItemHeightProperty { get; }public static DependencyProperty ItemHeightProperty { get; }Public Static ReadOnly Property ItemHeightProperty As DependencyProperty
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the ItemHeight dependency property.

Attributes

ItemWidth ItemWidth ItemWidth

Gets or sets the width of the layout area for each item that is contained in a WrapGrid.

public double ItemWidth { get; set; }public double ItemWidth { get; set; }Public ReadWrite Property ItemWidth As double
<WrapGrid ItemWidth="double" />
Value
double double double

The width of the layout area for each item that is contained in a WrapGrid. The default is Double.NaN, which results in the "Auto" layout behavior.

Attributes

Remarks

"Auto" layout and Double.NaN

The default value of ItemHeight and ItemWidth is not 0, it is Double.NaN. ItemHeight and ItemWidth support the ability to be an unset "Auto" value. Because ItemHeight and ItemWidth are Double values, Double.NaN is used as a special value to represent this "Auto" behavior. The layout system interprets the "Auto" value to generally mean that the object should be sized to the available size in layout, instead of to a specific pixel value. If you want the "Auto" behavior for an object when it is used in layout, leave ItemHeight and ItemWidth unset at their Double.NaN default value. If you have previously set values and want to reenable the "Auto" behavior with run-time code, set to Double.NaN. In XAML such as templates, you can set attribute values using the string "Auto".

Note

Visual C++ component extensions (C++/CX) doesn't have a constant for NaN, it uses a value, which appears as "-1.#IND" followed by zeros.

ItemWidthProperty ItemWidthProperty ItemWidthProperty

Identifies the ItemWidth dependency property.

public static DependencyProperty ItemWidthProperty { get; }public static DependencyProperty ItemWidthProperty { get; }Public Static ReadOnly Property ItemWidthProperty As DependencyProperty
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the ItemWidth dependency property.

Attributes

MaximumRowsOrColumns MaximumRowsOrColumns MaximumRowsOrColumns

Gets or sets a value that influences the wrap point, also accounting for Orientation.

public int MaximumRowsOrColumns { get; set; }public int MaximumRowsOrColumns { get; set; }Public ReadWrite Property MaximumRowsOrColumns As int
<WrapGrid MaximumRowsOrColumns="int" />
Value
int int int

The maximum rows or columns that this WrapGrid should present before it introduces wrapping to the layout. The default is -1, which is a special value that indicates no maximum.

Attributes

MaximumRowsOrColumnsProperty MaximumRowsOrColumnsProperty MaximumRowsOrColumnsProperty

Identifies the MaximumRowsOrColumns dependency property.

public static DependencyProperty MaximumRowsOrColumnsProperty { get; }public static DependencyProperty MaximumRowsOrColumnsProperty { get; }Public Static ReadOnly Property MaximumRowsOrColumnsProperty As DependencyProperty
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the MaximumRowsOrColumns dependency property.

Attributes

Orientation Orientation Orientation

Gets or sets the direction in which child elements are arranged.

public Orientation Orientation { get; set; }public Orientation Orientation { get; set; }Public ReadWrite Property Orientation As Orientation
WrapGrid Orientation="orientationMemberName" />
Value
Orientation Orientation Orientation

A value of the enumeration. The default is Vertical.

Attributes

Remarks

The Orientation property specifies whether the grid adds its items in rows or columns before wrapping.

When the value is Vertical, the grid adds items in columns from top to bottom, then wraps from left to right, like this:

Item 1Item 4Item 7
Item 2Item 5Item 8
Item 3Item 6Item 9

When the value is Horizontal, the grid adds items in rows from left to right, then wraps from top to bottom, like this:

Item 1Item 2Item 3
Item 4Item 5Item 6
Item 7Item 8Item 9

OrientationProperty OrientationProperty OrientationProperty

Identifies the Orientation dependency property.

public static DependencyProperty OrientationProperty { get; }public static DependencyProperty OrientationProperty { get; }Public Static ReadOnly Property OrientationProperty As DependencyProperty
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the Orientation dependency property.

Attributes

VerticalChildrenAlignment VerticalChildrenAlignment VerticalChildrenAlignment

Gets or sets the alignment rules by which child elements are arranged for the vertical dimension.

public VerticalAlignment VerticalChildrenAlignment { get; set; }public VerticalAlignment VerticalChildrenAlignment { get; set; }Public ReadWrite Property VerticalChildrenAlignment As VerticalAlignment
<WrapGrid VerticalChildrenAlignment="verticalAlignmentMemberName" />
Value
VerticalAlignment VerticalAlignment VerticalAlignment

A value of the enumeration. The default is Top.

Attributes

VerticalChildrenAlignmentProperty VerticalChildrenAlignmentProperty VerticalChildrenAlignmentProperty

Identifies the VerticalChildrenAlignment dependency property.

public static DependencyProperty VerticalChildrenAlignmentProperty { get; }public static DependencyProperty VerticalChildrenAlignmentProperty { get; }Public Static ReadOnly Property VerticalChildrenAlignmentProperty As DependencyProperty
Value
DependencyProperty DependencyProperty DependencyProperty

The identifier for the VerticalChildrenAlignment dependency property.

Attributes

See Also