Table of Contents

Class SelectionModel<T>

Namespace
Avalonia.Controls.Selection
Assembly
Avalonia.Controls.dll
public class SelectionModel<T> : SelectionNodeBase<T>, ISelectionModel, INotifyPropertyChanged

Type Parameters

T
Inheritance
SelectionModel<T>
Implements
Inherited Members
Extension Methods

Constructors

SelectionModel()

public SelectionModel()

SelectionModel(IEnumerable<T>?)

public SelectionModel(IEnumerable<T>? source)

Parameters

source IEnumerable<T>

Properties

AnchorIndex

public int AnchorIndex { get; set; }

Property Value

int

Count

public int Count { get; }

Property Value

int

SelectedIndex

public int SelectedIndex { get; set; }

Property Value

int

SelectedIndexes

public IReadOnlyList<int> SelectedIndexes { get; }

Property Value

IReadOnlyList<int>

SelectedItem

public T? SelectedItem { get; set; }

Property Value

T

SelectedItems

public IReadOnlyList<T?> SelectedItems { get; }

Property Value

IReadOnlyList<T>

SingleSelect

public bool SingleSelect { get; set; }

Property Value

bool

Source

public IEnumerable? Source { get; set; }

Property Value

IEnumerable

Methods

BatchUpdate()

public SelectionModel<T>.BatchUpdateOperation BatchUpdate()

Returns

SelectionModel<T>.BatchUpdateOperation

BeginBatchUpdate()

public void BeginBatchUpdate()

Clear()

public void Clear()

Deselect(int)

public void Deselect(int index)

Parameters

index int

DeselectRange(int, int)

public void DeselectRange(int start, int end)

Parameters

start int
end int

EndBatchUpdate()

public void EndBatchUpdate()

IsSelected(int)

public bool IsSelected(int index)

Parameters

index int

Returns

bool

OnIndexesChanged(int, int)

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

protected override 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 override 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 override 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 override 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 override void OnSourceCollectionChangeStarted()

OnSourceCollectionChanged(NotifyCollectionChangedEventArgs)

Called when the Source collection changes.

protected override 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 override void OnSourceReset()

RaisePropertyChanged(string)

protected void RaisePropertyChanged(string propertyName)

Parameters

propertyName string

Select(int)

public void Select(int index)

Parameters

index int

SelectAll()

public void SelectAll()

SelectRange(int, int)

public void SelectRange(int start, int end)

Parameters

start int
end int

Events

IndexesChanged

public event EventHandler<SelectionModelIndexesChangedEventArgs>? IndexesChanged

Event Type

EventHandler<SelectionModelIndexesChangedEventArgs>

LostSelection

public event EventHandler? LostSelection

Event Type

EventHandler

PropertyChanged

public event PropertyChangedEventHandler? PropertyChanged

Event Type

PropertyChangedEventHandler

SelectionChanged

public event EventHandler<SelectionModelSelectionChangedEventArgs<T>>? SelectionChanged

Event Type

EventHandler<SelectionModelSelectionChangedEventArgs<T>>

SourceReset

public event EventHandler? SourceReset

Event Type

EventHandler