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
-
IList<T>ICollection<T>IEnumerable<T>
- Derived
- Inherited Members
- Extension Methods
Remarks
AvaloniaList is similar to ObservableCollection<T> with a few added features:
- It can be configured to notify the CollectionChanged event with a Remove action instead of a Reset when the list is cleared by setting ResetBehavior to Remove.
- A Validate function can be used to validate each item before insertion.
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
intInitial 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
Count
Gets the number of items in the collection.
public int Count { get; }
Property Value
this[int]
Gets or sets the item at the specified index.
public T this[int index] { get; set; }
Parameters
index
intThe index.
Property Value
- T
The item.
ResetBehavior
Gets or sets the reset behavior of the list.
public ResetBehavior ResetBehavior { get; set; }
Property Value
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
TThe 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
TThe 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
intThe 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
intThe capacity.
GetEnumerator()
public AvaloniaList<T>.Enumerator GetEnumerator()
Returns
GetRange(int, int)
Gets a range of items from the collection.
public IEnumerable<T> GetRange(int index, int count)
Parameters
index
intThe zero-based AvaloniaList<T> index at which the range starts.
count
intThe 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
TThe 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
intThe index.
item
TThe item.
InsertRange(int, IEnumerable<T>)
Inserts multiple items at the specified index.
public virtual void InsertRange(int index, IEnumerable<T> items)
Parameters
index
intThe index.
items
IEnumerable<T>The items.
Move(int, int)
Moves an item to a new index.
public void Move(int oldIndex, int newIndex)
Parameters
MoveRange(int, int, int)
Moves multiple items to a new index.
public void MoveRange(int oldIndex, int count, int newIndex)
Parameters
oldIndex
intThe first index of the items to move.
count
intThe number of items to move.
newIndex
intThe index to move the items to.
Remove(T)
Removes an item from the collection.
public virtual bool Remove(T item)
Parameters
item
TThe 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
intThe index.
RemoveRange(int, int)
Removes a range of elements from the collection.
public virtual void RemoveRange(int index, int count)
Parameters
Events
CollectionChanged
Raised when a change is made to the collection's items.
public event NotifyCollectionChangedEventHandler? CollectionChanged
Event Type
PropertyChanged
Raised when a property on the collection changes.
public event PropertyChangedEventHandler? PropertyChanged