Class VirtualizingVariableSizeWrapPanel
A virtualizing panel that arranges children in a variable-size grid layout. Items can span multiple columns and rows, creating flexible tile-based layouts. Only items within the visible viewport (plus buffer) are materialized for optimal performance.
public class VirtualizingVariableSizeWrapPanel : VirtualizingPanel, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue, IChildIndexProvider, INavigableContainer
- Inheritance
-
AvaloniaObjectAnimatableStyledElementVisualLayoutableInteractiveInputElementControlPanelVirtualizingPanelVirtualizingVariableSizeWrapPanel
- Implements
-
IDataContextProviderILogicalIThemeVariantHostIResourceHostIResourceNodeIStyleHostISetLogicalParentISetInheritanceParentIStyleableINamedIInputElementIDataTemplateHostISetterValueIChildIndexProviderINavigableContainer
- Inherited Members
-
VirtualizingPanel.OnItemsControlChanged(ItemsControl)VirtualizingPanel.AddInternalChild(Control)VirtualizingPanel.RemoveInternalChild(Control)VirtualizingPanel.ItemContainerGeneratorVirtualizingPanel.ItemsVirtualizingPanel.ItemsControlPanel.BackgroundPropertyPanel.Render(DrawingContext)Panel.AffectsParentArrange<TPanel>(params AvaloniaProperty[])Panel.AffectsParentMeasure<TPanel>(params AvaloniaProperty[])Panel.ChildrenPanel.BackgroundPanel.IsItemsHostControl.FocusAdornerPropertyControl.TagPropertyControl.ContextMenuPropertyControl.ContextFlyoutPropertyControl.RequestBringIntoViewEventControl.ContextRequestedEventControl.LoadedEventControl.UnloadedEventControl.SizeChangedEventControl.GetTemplateFocusTarget()Control.OnLoaded(RoutedEventArgs)Control.OnUnloaded(RoutedEventArgs)Control.OnSizeChanged(SizeChangedEventArgs)Control.OnAttachedToVisualTreeCore(VisualTreeAttachmentEventArgs)Control.OnDetachedFromVisualTreeCore(VisualTreeAttachmentEventArgs)Control.OnGotFocus(GotFocusEventArgs)Control.OnLostFocus(RoutedEventArgs)Control.OnCreateAutomationPeer()Control.OnPointerReleased(PointerReleasedEventArgs)Control.OnKeyUp(KeyEventArgs)Control.FocusAdornerControl.DataTemplatesControl.ContextMenuControl.ContextFlyoutControl.IsLoadedControl.TagControl.ContextRequestedControl.LoadedControl.UnloadedControl.SizeChangedInputElement.FocusablePropertyInputElement.IsEnabledPropertyInputElement.IsEffectivelyEnabledPropertyInputElement.CursorPropertyInputElement.IsKeyboardFocusWithinPropertyInputElement.IsFocusedPropertyInputElement.IsHitTestVisiblePropertyInputElement.IsPointerOverPropertyInputElement.IsTabStopPropertyInputElement.GotFocusEventInputElement.LostFocusEventInputElement.KeyDownEventInputElement.KeyUpEventInputElement.TabIndexPropertyInputElement.TextInputEventInputElement.TextInputMethodClientRequestedEventInputElement.PointerEnteredEventInputElement.PointerExitedEventInputElement.PointerMovedEventInputElement.PointerPressedEventInputElement.PointerReleasedEventInputElement.PointerCaptureLostEventInputElement.PointerWheelChangedEventInputElement.TappedEventInputElement.HoldingEventInputElement.DoubleTappedEventInputElement.Focus(NavigationMethod, KeyModifiers)InputElement.OnAccessKey(RoutedEventArgs)InputElement.OnKeyDown(KeyEventArgs)InputElement.OnTextInput(TextInputEventArgs)InputElement.OnPointerEntered(PointerEventArgs)InputElement.OnPointerExited(PointerEventArgs)InputElement.OnPointerMoved(PointerEventArgs)InputElement.OnPointerPressed(PointerPressedEventArgs)InputElement.OnPointerCaptureLost(PointerCaptureLostEventArgs)InputElement.OnPointerWheelChanged(PointerWheelEventArgs)InputElement.UpdateIsEffectivelyEnabled()InputElement.FocusableInputElement.IsEnabledInputElement.CursorInputElement.IsKeyboardFocusWithinInputElement.IsFocusedInputElement.IsHitTestVisibleInputElement.IsPointerOverInputElement.IsTabStopInputElement.IsEffectivelyEnabledInputElement.TabIndexInputElement.KeyBindingsInputElement.IsEnabledCoreInputElement.GestureRecognizersInputElement.GotFocusInputElement.LostFocusInputElement.KeyDownInputElement.KeyUpInputElement.TextInputInputElement.TextInputMethodClientRequestedInputElement.PointerEnteredInputElement.PointerExitedInputElement.PointerMovedInputElement.PointerPressedInputElement.PointerReleasedInputElement.PointerCaptureLostInputElement.PointerWheelChangedInputElement.TappedInputElement.HoldingInputElement.DoubleTappedInteractive.RaiseEvent(RoutedEventArgs)Interactive.BuildEventRoute(RoutedEvent)Layoutable.DesiredSizePropertyLayoutable.WidthPropertyLayoutable.HeightPropertyLayoutable.MinWidthPropertyLayoutable.MaxWidthPropertyLayoutable.MinHeightPropertyLayoutable.MaxHeightPropertyLayoutable.MarginPropertyLayoutable.HorizontalAlignmentPropertyLayoutable.VerticalAlignmentPropertyLayoutable.UseLayoutRoundingPropertyLayoutable.UpdateLayout()Layoutable.ApplyTemplate()Layoutable.Measure(Size)Layoutable.Arrange(Rect)Layoutable.InvalidateMeasure()Layoutable.InvalidateArrange()Layoutable.AffectsMeasure<T>(params AvaloniaProperty[])Layoutable.AffectsArrange<T>(params AvaloniaProperty[])Layoutable.MeasureCore(Size)Layoutable.ArrangeCore(Rect)Layoutable.OnMeasureInvalidated()Layoutable.OnVisualParentChanged(Visual, Visual)Layoutable.WidthLayoutable.HeightLayoutable.MinWidthLayoutable.MaxWidthLayoutable.MinHeightLayoutable.MaxHeightLayoutable.MarginLayoutable.HorizontalAlignmentLayoutable.VerticalAlignmentLayoutable.DesiredSizeLayoutable.IsMeasureValidLayoutable.IsArrangeValidLayoutable.UseLayoutRoundingLayoutable.EffectiveViewportChangedLayoutable.LayoutUpdatedVisual.BoundsPropertyVisual.ClipToBoundsPropertyVisual.ClipPropertyVisual.IsVisiblePropertyVisual.OpacityPropertyVisual.OpacityMaskPropertyVisual.EffectPropertyVisual.HasMirrorTransformPropertyVisual.RenderTransformPropertyVisual.RenderTransformOriginPropertyVisual.FlowDirectionPropertyVisual.VisualParentPropertyVisual.ZIndexPropertyVisual.GetFlowDirection(Visual)Visual.SetFlowDirection(Visual, FlowDirection)Visual.InvalidateVisual()Visual.AffectsRender<T>(params AvaloniaProperty[])Visual.InvalidateMirrorTransform()Visual.BoundsVisual.ClipToBoundsVisual.ClipVisual.IsEffectivelyVisibleVisual.IsVisibleVisual.OpacityVisual.OpacityMaskVisual.EffectVisual.HasMirrorTransformVisual.RenderTransformVisual.RenderTransformOriginVisual.FlowDirectionVisual.ZIndexVisual.VisualChildrenVisual.VisualRootVisual.BypassFlowDirectionPoliciesVisual.AttachedToVisualTreeVisual.DetachedFromVisualTreeStyledElement.DataContextPropertyStyledElement.NamePropertyStyledElement.ParentPropertyStyledElement.TemplatedParentPropertyStyledElement.ThemePropertyStyledElement.BeginInit()StyledElement.EndInit()StyledElement.ApplyStyling()StyledElement.InitializeIfNeeded()StyledElement.OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs)StyledElement.OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs)StyledElement.OnDataContextBeginUpdate()StyledElement.OnDataContextEndUpdate()StyledElement.OnInitialized()StyledElement.NameStyledElement.ClassesStyledElement.DataContextStyledElement.IsInitializedStyledElement.StylesStyledElement.StyleKeyStyledElement.ResourcesStyledElement.TemplatedParentStyledElement.ThemeStyledElement.LogicalChildrenStyledElement.PseudoClassesStyledElement.StyleKeyOverrideStyledElement.ParentStyledElement.ActualThemeVariantStyledElement.AttachedToLogicalTreeStyledElement.DetachedFromLogicalTreeStyledElement.DataContextChangedStyledElement.InitializedStyledElement.ResourcesChangedStyledElement.ActualThemeVariantChangedAnimatable.TransitionsPropertyAnimatable.OnPropertyChangedCore(AvaloniaPropertyChangedEventArgs)Animatable.TransitionsAvaloniaObject.CheckAccess()AvaloniaObject.VerifyAccess()AvaloniaObject.ClearValue(AvaloniaProperty)AvaloniaObject.ClearValue<T>(AvaloniaProperty<T>)AvaloniaObject.ClearValue<T>(StyledProperty<T>)AvaloniaObject.ClearValue<T>(DirectPropertyBase<T>)AvaloniaObject.GetHashCode()AvaloniaObject.GetValue(AvaloniaProperty)AvaloniaObject.GetValue<T>(StyledProperty<T>)AvaloniaObject.GetValue<T>(DirectPropertyBase<T>)AvaloniaObject.GetBaseValue<T>(StyledProperty<T>)AvaloniaObject.IsAnimating(AvaloniaProperty)AvaloniaObject.IsSet(AvaloniaProperty)AvaloniaObject.SetValue<T>(StyledProperty<T>, T, BindingPriority)AvaloniaObject.SetValue<T>(DirectPropertyBase<T>, T)AvaloniaObject.SetCurrentValue<T>(StyledProperty<T>, T)AvaloniaObject.Bind(AvaloniaProperty, IBinding)AvaloniaObject.CoerceValue(AvaloniaProperty)AvaloniaObject.RaisePropertyChanged<T>(DirectPropertyBase<T>, T, T)AvaloniaObject.SetAndRaise<T>(DirectPropertyBase<T>, ref T, T)AvaloniaObject.InheritanceParentAvaloniaObject.this[AvaloniaProperty]AvaloniaObject.this[IndexerDescriptor]AvaloniaObject.PropertyChanged
Examples
<ItemsControl ItemsSource="{Binding Items}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<controls:VirtualizingVariableSizeWrapPanel Columns="4" TileSize="100" Spacing="8"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
Remarks
This panel virtualizes items by only creating UI containers for visible items. Off-screen items are recycled and reused when scrolling, minimizing memory usage and improving scroll performance for large datasets.
Use the ColumnSpanProperty and RowSpanProperty attached properties on child elements to control their size in the grid.
Constructors
VirtualizingVariableSizeWrapPanel()
public VirtualizingVariableSizeWrapPanel()
Fields
ColumnSpanProperty
Defines the ColumnSpan attached property.
public static readonly AttachedProperty<int> ColumnSpanProperty
Field Value
- AttachedProperty<int>
ColumnsProperty
Defines the Columns property.
public static readonly StyledProperty<int> ColumnsProperty
Field Value
- StyledProperty<int>
RowSpanProperty
Defines the RowSpan attached property.
public static readonly AttachedProperty<int> RowSpanProperty
Field Value
- AttachedProperty<int>
SpacingProperty
Defines the Spacing property.
public static readonly StyledProperty<double> SpacingProperty
Field Value
- StyledProperty<double>
TileSizeProperty
Defines the TileSize property.
public static readonly StyledProperty<double> TileSizeProperty
Field Value
- StyledProperty<double>
Properties
Columns
Gets or sets the number of columns in the grid.
public int Columns { get; set; }
Property Value
- int
The number of columns. Default is 4.
Spacing
Gets or sets the spacing between tiles in both directions.
public double Spacing { get; set; }
Property Value
- double
The spacing in device-independent pixels. Default is 8.
TileSize
Gets or sets the size of a single tile (both width and height for a 1x1 item).
public double TileSize { get; set; }
Property Value
- double
The tile size in device-independent pixels. Default is 100.
Methods
ArrangeOverride(Size)
Positions child elements as part of a layout pass.
protected override Size ArrangeOverride(Size finalSize)
Parameters
finalSizeSizeThe size available to the control.
Returns
- Size
The actual size used.
ContainerFromIndex(int)
Returns the container for the item at the specified index.
protected override Control? ContainerFromIndex(int index)
Parameters
indexintThe index of the item to retrieve.
Returns
- Control
The container for the item at the specified index within the item collection, if the item is realized; otherwise, null.
Remarks
Note for implementors: if the item at the specified index is an ItemIsOwnContainer item that has previously been realized, then the item should be returned even if it currently falls outside the realized viewport.
GetColumnSpan(Control)
Gets the number of columns an element should span.
public static int GetColumnSpan(Control element)
Parameters
elementControlThe element to get the column span for.
Returns
- int
The number of columns the element spans.
GetControl(NavigationDirection, IInputElement?, bool)
Gets the next control in the specified direction.
protected override Control? GetControl(NavigationDirection direction, IInputElement? from, bool wrap)
Parameters
directionNavigationDirectionThe movement direction.
fromIInputElementThe control from which movement begins.
wrapboolWhether to wrap around when the first or last item is reached.
Returns
- Control
The control.
GetRealizedContainers()
Gets the currently realized containers.
protected override IEnumerable<Control>? GetRealizedContainers()
Returns
- IEnumerable<Control>
GetRowSpan(Control)
Gets the number of rows an element should span.
public static int GetRowSpan(Control element)
Parameters
elementControlThe element to get the row span for.
Returns
- int
The number of rows the element spans.
IndexFromContainer(Control)
Returns the index to the item that has the specified realized container.
protected override int IndexFromContainer(Control container)
Parameters
containerControlThe generated container to retrieve the item index for.
Returns
- int
The index to the item that corresponds to the specified realized container, or -1 if
containeris not found.
MeasureOverride(Size)
Measures the control and its child elements as part of a layout pass.
protected override Size MeasureOverride(Size availableSize)
Parameters
availableSizeSizeThe size available to the control.
Returns
- Size
The desired size for the control.
OnAttachedToVisualTree(VisualTreeAttachmentEventArgs)
Called when the control is added to a rooted visual tree.
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
Parameters
eVisualTreeAttachmentEventArgsThe event args.
OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs)
Called when the control is removed from a rooted visual tree.
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
Parameters
eVisualTreeAttachmentEventArgsThe event args.
OnItemsChanged(IReadOnlyList<object?>, NotifyCollectionChangedEventArgs)
Called when the Avalonia.Controls.ItemsControl.Items collection of the owner Avalonia.Controls.VirtualizingPanel.ItemsControl changes.
protected override void OnItemsChanged(IReadOnlyList<object?> items, NotifyCollectionChangedEventArgs e)
Parameters
itemsIReadOnlyList<object>The items.
eNotifyCollectionChangedEventArgsThe event args.
Remarks
This method is called a INotifyCollectionChanged event is raised by the items, or when the Avalonia.Controls.ItemsControl.Items property is assigned a new collection, in which case the NotifyCollectionChangedAction will be Reset.
OnPropertyChanged(AvaloniaPropertyChangedEventArgs)
Called when a avalonia property changes on the object.
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
Parameters
changeAvaloniaPropertyChangedEventArgsThe property change details.
ScrollIntoView(int)
Scrolls the specified item into view.
protected override Control? ScrollIntoView(int index)
Parameters
indexintThe index of the item.
Returns
- Control
The element with the specified index, or null if the element could not be brought into view.
SetColumnSpan(Control, int)
Sets the number of columns an element should span.
public static void SetColumnSpan(Control element, int value)
Parameters
elementControlThe element to set the column span for.
valueintThe number of columns to span.
SetRowSpan(Control, int)
Sets the number of rows an element should span.
public static void SetRowSpan(Control element, int value)
Parameters
elementControlThe element to set the row span for.
valueintThe number of rows to span.