Table of Contents

Class VirtualizingStackPanel

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

Arranges and virtualizes content on a single line that is oriented either horizontally or vertically.

public class VirtualizingStackPanel : VirtualizingPanel, INotifyPropertyChanged, IDataContextProvider, ILogical, IThemeVariantHost, IResourceHost, IResourceNode, IStyleHost, ISetLogicalParent, ISetInheritanceParent, ISupportInitialize, IStyleable, INamed, IInputElement, IDataTemplateHost, ISetterValue, IChildIndexProvider, INavigableContainer, IScrollSnapPointsInfo
Inheritance
VirtualizingStackPanel
Implements
Inherited Members
Extension Methods

Constructors

VirtualizingStackPanel()

public VirtualizingStackPanel()

Fields

AreHorizontalSnapPointsRegularProperty

Defines the AreHorizontalSnapPointsRegular property.

public static readonly StyledProperty<bool> AreHorizontalSnapPointsRegularProperty

Field Value

StyledProperty<bool>

AreVerticalSnapPointsRegularProperty

Defines the AreVerticalSnapPointsRegular property.

public static readonly StyledProperty<bool> AreVerticalSnapPointsRegularProperty

Field Value

StyledProperty<bool>

HorizontalSnapPointsChangedEvent

Defines the HorizontalSnapPointsChanged event.

public static readonly RoutedEvent<RoutedEventArgs> HorizontalSnapPointsChangedEvent

Field Value

RoutedEvent<RoutedEventArgs>

OrientationProperty

Defines the Orientation property.

public static readonly StyledProperty<Orientation> OrientationProperty

Field Value

StyledProperty<Orientation>

VerticalSnapPointsChangedEvent

Defines the VerticalSnapPointsChanged event.

public static readonly RoutedEvent<RoutedEventArgs> VerticalSnapPointsChangedEvent

Field Value

RoutedEvent<RoutedEventArgs>

Properties

AreHorizontalSnapPointsRegular

Gets or sets whether the horizontal snap points for the VirtualizingStackPanel are equidistant from each other.

public bool AreHorizontalSnapPointsRegular { get; set; }

Property Value

bool

AreVerticalSnapPointsRegular

Gets or sets whether the vertical snap points for the VirtualizingStackPanel are equidistant from each other.

public bool AreVerticalSnapPointsRegular { get; set; }

Property Value

bool

FirstRealizedIndex

Gets the index of the first realized element, or -1 if no elements are realized.

public int FirstRealizedIndex { get; }

Property Value

int

LastRealizedIndex

Gets the index of the last realized element, or -1 if no elements are realized.

public int LastRealizedIndex { get; }

Property Value

int

Orientation

Gets or sets the axis along which items are laid out.

public Orientation Orientation { get; set; }

Property Value

Orientation

One of the enumeration values that specifies the axis along which items are laid out. The default is Vertical.

Methods

ArrangeOverride(Size)

Positions child elements as part of a layout pass.

protected override Size ArrangeOverride(Size finalSize)

Parameters

finalSize Size

The 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

index int

The 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.

GetControl(NavigationDirection, IInputElement?, bool)

Gets the next control in the specified direction.

protected override IInputElement? GetControl(NavigationDirection direction, IInputElement? from, bool wrap)

Parameters

direction NavigationDirection

The movement direction.

from IInputElement

The control from which movement begins.

wrap bool

Whether to wrap around when the first or last item is reached.

Returns

IInputElement

The control.

GetIrregularSnapPoints(Orientation, SnapPointsAlignment)

Returns the set of distances between irregular snap points for a specified orientation and alignment.

public IReadOnlyList<double> GetIrregularSnapPoints(Orientation orientation, SnapPointsAlignment snapPointsAlignment)

Parameters

orientation Orientation

The orientation for the desired snap point set.

snapPointsAlignment SnapPointsAlignment

The alignment to use when applying the snap points.

Returns

IReadOnlyList<double>

The read-only collection of snap point distances. Returns an empty collection when no snap points are present.

GetRealizedContainers()

Gets the currently realized containers.

protected override IEnumerable<Control>? GetRealizedContainers()

Returns

IEnumerable<Control>

GetRegularSnapPoints(Orientation, SnapPointsAlignment, out double)

Gets the distance between regular snap points for a specified orientation and alignment.

public double GetRegularSnapPoints(Orientation orientation, SnapPointsAlignment snapPointsAlignment, out double offset)

Parameters

orientation Orientation

The orientation for the desired snap point set.

snapPointsAlignment SnapPointsAlignment

The alignment to use when applying the snap points.

offset double

Out parameter. The offset of the first snap point.

Returns

double

The distance between the equidistant snap points. Returns 0 when no snap points are present.

IndexFromContainer(Control)

Returns the index to the item that has the specified realized container.

protected override int IndexFromContainer(Control container)

Parameters

container Control

The 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 container is not found.

MeasureOverride(Size)

Measures the control and its child elements as part of a layout pass.

protected override Size MeasureOverride(Size availableSize)

Parameters

availableSize Size

The 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

e VisualTreeAttachmentEventArgs

The event args.

OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs)

Called when the control is removed from a rooted visual tree.

protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)

Parameters

e VisualTreeAttachmentEventArgs

The event args.

OnItemsChanged(IReadOnlyList<object?>, NotifyCollectionChangedEventArgs)

Called when the Items collection of the owner ItemsControl changes.

protected override void OnItemsChanged(IReadOnlyList<object?> items, NotifyCollectionChangedEventArgs e)

Parameters

items IReadOnlyList<object>

The items.

e NotifyCollectionChangedEventArgs

The event args.

Remarks

This method is called a INotifyCollectionChanged event is raised by the items, or when the Items property is assigned a new collection, in which case the NotifyCollectionChangedAction will be Reset.

OnItemsControlChanged(ItemsControl?)

Called when the ItemsControl that owns the panel changes.

protected override void OnItemsControlChanged(ItemsControl? oldValue)

Parameters

oldValue ItemsControl

The old value of the ItemsControl property.

ScrollIntoView(int)

Scrolls the specified item into view.

protected override Control? ScrollIntoView(int index)

Parameters

index int

The index of the item.

Returns

Control

The element with the specified index, or null if the element could not be brought into view.

Events

HorizontalSnapPointsChanged

Occurs when the measurements for horizontal snap points change.

public event EventHandler<RoutedEventArgs>? HorizontalSnapPointsChanged

Event Type

EventHandler<RoutedEventArgs>

VerticalSnapPointsChanged

Occurs when the measurements for vertical snap points change.

public event EventHandler<RoutedEventArgs>? VerticalSnapPointsChanged

Event Type

EventHandler<RoutedEventArgs>