Table of Contents

Class VirtualizingPanel

Namespace
Avalonia.Controls
Assembly
Avalonia.Controls.dll

Base class for panels that can be used to virtualize items for an ItemsControl.

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

Remarks

Panels should implement the abstract members of this class to provide virtualization of items in a ItemsControl. Derived panels can manage scrolling by implementing ILogicalScrollable or by listening to the EffectiveViewportChanged event.

The methods on the ItemContainerGenerator should be used to create, prepare and clear containers for items.

Constructors

VirtualizingPanel()

protected VirtualizingPanel()

Properties

ItemContainerGenerator

public ItemContainerGenerator? ItemContainerGenerator { get; }

Property Value

ItemContainerGenerator

Items

Gets the items to display.

protected IReadOnlyList<object?> Items { get; }

Property Value

IReadOnlyList<object>

ItemsControl

Gets the ItemsControl that the panel is displaying items for.

protected ItemsControl? ItemsControl { get; }

Property Value

ItemsControl

Methods

AddInternalChild(Control)

Adds the specified Control to the Children collection of a VirtualizingPanel element.

protected void AddInternalChild(Control control)

Parameters

control Control

The control to add to the collection.

ContainerFromIndex(int)

Returns the container for the item at the specified index.

protected abstract 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 abstract 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.

GetRealizedContainers()

Gets the currently realized containers.

protected abstract IEnumerable<Control>? GetRealizedContainers()

Returns

IEnumerable<Control>

IndexFromContainer(Control)

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

protected abstract 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.

InsertInternalChild(int, Control)

Adds the specified Control to the Children collection of a VirtualizingPanel element at the specified index position.

protected void InsertInternalChild(int index, Control control)

Parameters

index int

The index position within the collection at which the child element is inserted.

control Control

The control to add to the collection.

OnItemsChanged(IReadOnlyList<object?>, NotifyCollectionChangedEventArgs)

Called when the Items collection of the owner ItemsControl changes.

protected virtual 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 virtual void OnItemsControlChanged(ItemsControl? oldValue)

Parameters

oldValue ItemsControl

The old value of the ItemsControl property.

RemoveInternalChild(Control)

Removes a child element from the Children collection.

protected void RemoveInternalChild(Control child)

Parameters

child Control

The child to remove/

RemoveInternalChildRange(int, int)

Removes child elements from the Children collection.

protected void RemoveInternalChildRange(int index, int count)

Parameters

index int

The beginning index position within the collection at which the first child element is removed.

count int

The number of child elements to remove.

ScrollIntoView(int)

Scrolls the specified item into view.

protected abstract 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.