Class VirtualizingPanel
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
Gets the ItemContainerGenerator for this VirtualizingPanel.
public ItemContainerGenerator? ItemContainerGenerator { get; }
Property Value
Items
Gets the items to display.
protected IReadOnlyList<object?> Items { get; }
Property Value
ItemsControl
Gets the ItemsControl that the panel is displaying items for.
protected ItemsControl? ItemsControl { get; }
Property Value
Methods
AddInternalChild(Control)
Adds the specified Control to the Children collection of a VirtualizingPanel element.
protected void AddInternalChild(Control control)
Parameters
control
ControlThe 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
intThe 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
NavigationDirectionThe movement direction.
from
IInputElementThe control from which movement begins.
wrap
boolWhether 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
IndexFromContainer(Control)
Returns the index to the item that has the specified realized container.
protected abstract int IndexFromContainer(Control container)
Parameters
container
ControlThe 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
intThe index position within the collection at which the child element is inserted.
control
ControlThe 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
NotifyCollectionChangedEventArgsThe 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
ItemsControlThe old value of the ItemsControl property.
RemoveInternalChild(Control)
Removes a child element from the Children collection.
protected void RemoveInternalChild(Control child)
Parameters
child
ControlThe child to remove/
RemoveInternalChildRange(int, int)
Removes child elements from the Children collection.
protected void RemoveInternalChildRange(int index, int count)
Parameters
index
intThe beginning index position within the collection at which the first child element is removed.
count
intThe number of child elements to remove.
ScrollIntoView(int)
Scrolls the specified item into view.
protected abstract Control? ScrollIntoView(int index)
Parameters
index
intThe index of the item.
Returns
- Control
The element with the specified index, or null if the element could not be brought into view.