Table of Contents

Class SelectionNodeBase<T>

Namespace
Avalonia.Controls.Selection
Assembly
Avalonia.Controls.dll

Base class for selection models.

public abstract class SelectionNodeBase<T>

Type Parameters

T

The type of the element being selected.

Inheritance
SelectionNodeBase<T>
Derived
Inherited Members

Constructors

SelectionNodeBase()

protected SelectionNodeBase()

Properties

ItemsView

Gets an ItemsSourceView<T> of the Source.

protected ItemsSourceView<T>? ItemsView { get; set; }

Property Value

ItemsSourceView<T>

RangesEnabled

Gets or sets a value indicating whether range selection is currently enabled for the selection node.

protected bool RangesEnabled { get; set; }

Property Value

bool

Source

Gets or sets the source collection.

protected IEnumerable? Source { get; set; }

Property Value

IEnumerable

Methods

CommitDeselect(int, int)

If RangesEnabled, removes the specified range from the selection.

protected int CommitDeselect(int begin, int end)

Parameters

begin int

The inclusive index of the start of the range to deselect.

end int

The inclusive index of the end of the range to deselect.

Returns

int

The number of items selected.

CommitSelect(int, int)

If RangesEnabled, adds the specified range to the selection.

protected int CommitSelect(int begin, int end)

Parameters

begin int

The inclusive index of the start of the range to select.

end int

The inclusive index of the end of the range to select.

Returns

int

The number of items selected.

OnIndexesChanged(int, int)

Called by OnSourceCollectionChanged(NotifyCollectionChangedEventArgs), detailing the indexes changed by the collection changing.

protected virtual void OnIndexesChanged(int shiftIndex, int shiftDelta)

Parameters

shiftIndex int

The first index that was shifted.

shiftDelta int

If positive, the number of items inserted, or if negative the number of items removed.

OnItemsAdded(int, IList)

Called by OnSourceCollectionChanged(NotifyCollectionChangedEventArgs) when items are added to the source collection.

protected virtual SelectionNodeBase<T>.CollectionChangeState OnItemsAdded(int index, IList items)

Parameters

index int
items IList

Returns

SelectionNodeBase<T>.CollectionChangeState

A SelectionNodeBase<T>.CollectionChangeState struct containing the details of the adjusted selection.

Remarks

The implementation in SelectionNodeBase<T> adjusts the selected ranges, assigning new indexes. Override this method to carry out additional computation when items are added.

OnSelectionRemoved(int, int, IReadOnlyList<T>)

Called by OnSourceCollectionChanged(NotifyCollectionChangedEventArgs), detailing the items removed by a collection change.

protected virtual void OnSelectionRemoved(int index, int count, IReadOnlyList<T> deselectedItems)

Parameters

index int
count int
deselectedItems IReadOnlyList<T>

OnSourceCollectionChangeFinished()

Called when the source collection has finished changing, and all CollectionChanged handlers have run.

protected virtual void OnSourceCollectionChangeFinished()

Remarks

Override this method to respond to the end of a collection change instead of acting at the end of OnSourceCollectionChanged(NotifyCollectionChangedEventArgs) in order to ensure that all UI subscribers to the source collection change event have had chance to run.

OnSourceCollectionChangeStarted()

Called when the source collection starts changing.

protected virtual void OnSourceCollectionChangeStarted()

OnSourceCollectionChanged(NotifyCollectionChangedEventArgs)

Called when the Source collection changes.

protected virtual void OnSourceCollectionChanged(NotifyCollectionChangedEventArgs e)

Parameters

e NotifyCollectionChangedEventArgs

The details of the collection change.

Remarks

The implementation in SelectionNodeBase<T> calls OnItemsAdded(int, IList) and OnItemsRemoved(int, IList) in order to calculate how the collection change affects the currently selected items. It then calls OnIndexesChanged(int, int) and OnSelectionRemoved(int, int, IReadOnlyList<T>) if necessary, according to the SelectionNodeBase<T>.CollectionChangeState returned by those methods.

Override this method and OnSourceCollectionChangeFinished() to provide custom handling of source collection changes.

OnSourceReset()

protected abstract void OnSourceReset()