Table of Contents

Class AvaloniaList<T>

Namespace
Avalonia.Collections
Assembly
Avalonia.Base.dll

A notifying list.

public class AvaloniaList<T> : IAvaloniaList<T>, IList<T>, ICollection<T>, IAvaloniaReadOnlyList<T>, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, INotifyCollectionChanged, INotifyPropertyChanged, IList, ICollection, IEnumerable

Type Parameters

T

The type of the list items.

Inheritance
AvaloniaList<T>
Implements
Derived
Inherited Members
Extension Methods

Remarks

AvaloniaList is similar to ObservableCollection<T> with a few added features:

Constructors

AvaloniaList()

Initializes a new instance of the AvaloniaList<T> class.

public AvaloniaList()

AvaloniaList(IEnumerable<T>)

Initializes a new instance of the AvaloniaList<T> class.

public AvaloniaList(IEnumerable<T> items)

Parameters

items IEnumerable<T>

The initial items for the collection.

AvaloniaList(int)

Initializes a new instance of the AvaloniaList<T>.

public AvaloniaList(int capacity)

Parameters

capacity int

Initial list capacity.

AvaloniaList(params T[])

Initializes a new instance of the AvaloniaList<T> class.

public AvaloniaList(params T[] items)

Parameters

items T[]

The initial items for the collection.

Properties

Capacity

Gets or sets the total number of elements the internal data structure can hold without resizing.

public int Capacity { get; set; }

Property Value

int

Count

Gets the number of items in the collection.

public int Count { get; }

Property Value

int

this[int]

Gets or sets the item at the specified index.

public T this[int index] { get; set; }

Parameters

index int

The index.

Property Value

T

The item.

ResetBehavior

Gets or sets the reset behavior of the list.

public ResetBehavior ResetBehavior { get; set; }

Property Value

ResetBehavior

Validate

Gets or sets a validation routine that can be used to validate items before they are added.

public Action<T>? Validate { get; set; }

Property Value

Action<T>

Methods

Add(T)

Adds an item to the collection.

public virtual void Add(T item)

Parameters

item T

The item.

AddRange(IEnumerable<T>)

Adds multiple items to the collection.

public virtual void AddRange(IEnumerable<T> items)

Parameters

items IEnumerable<T>

The items.

Clear()

Removes all items from the collection.

public virtual void Clear()

Contains(T)

Tests if the collection contains the specified item.

public bool Contains(T item)

Parameters

item T

The item.

Returns

bool

True if the collection contains the item; otherwise false.

CopyTo(T[], int)

Copies the collection's contents to an array.

public void CopyTo(T[] array, int arrayIndex)

Parameters

array T[]

The array.

arrayIndex int

The first index of the array to copy to.

EnsureCapacity(int)

Ensures that the capacity of the list is at least Capacity.

public void EnsureCapacity(int capacity)

Parameters

capacity int

The capacity.

GetEnumerator()

public AvaloniaList<T>.Enumerator GetEnumerator()

Returns

AvaloniaList<T>.Enumerator

GetRange(int, int)

Gets a range of items from the collection.

public IEnumerable<T> GetRange(int index, int count)

Parameters

index int

The zero-based AvaloniaList<T> index at which the range starts.

count int

The number of elements in the range.

Returns

IEnumerable<T>

IndexOf(T)

Gets the index of the specified item in the collection.

public int IndexOf(T item)

Parameters

item T

The item.

Returns

int

The index of the item or -1 if the item is not contained in the collection.

Insert(int, T)

Inserts an item at the specified index.

public virtual void Insert(int index, T item)

Parameters

index int

The index.

item T

The item.

InsertRange(int, IEnumerable<T>)

Inserts multiple items at the specified index.

public virtual void InsertRange(int index, IEnumerable<T> items)

Parameters

index int

The index.

items IEnumerable<T>

The items.

Move(int, int)

Moves an item to a new index.

public void Move(int oldIndex, int newIndex)

Parameters

oldIndex int

The index of the item to move.

newIndex int

The index to move the item to.

MoveRange(int, int, int)

Moves multiple items to a new index.

public void MoveRange(int oldIndex, int count, int newIndex)

Parameters

oldIndex int

The first index of the items to move.

count int

The number of items to move.

newIndex int

The index to move the items to.

Remove(T)

Removes an item from the collection.

public virtual bool Remove(T item)

Parameters

item T

The item.

Returns

bool

True if the item was found and removed, otherwise false.

RemoveAll(IEnumerable<T>)

Removes multiple items from the collection.

public virtual void RemoveAll(IEnumerable<T> items)

Parameters

items IEnumerable<T>

The items.

RemoveAt(int)

Removes the item at the specified index.

public virtual void RemoveAt(int index)

Parameters

index int

The index.

RemoveRange(int, int)

Removes a range of elements from the collection.

public virtual void RemoveRange(int index, int count)

Parameters

index int

The first index to remove.

count int

The number of items to remove.

Events

CollectionChanged

Raised when a change is made to the collection's items.

public event NotifyCollectionChangedEventHandler? CollectionChanged

Event Type

NotifyCollectionChangedEventHandler

PropertyChanged

Raised when a property on the collection changes.

public event PropertyChangedEventHandler? PropertyChanged

Event Type

PropertyChangedEventHandler