Class ItemsSourceCollection
A collection which can retrieve its items from an items source, if specified. If not, it behaves like a normal collection to which any item can be added.
Namespace: Celestial.UIToolkit
Assembly: Celestial.UIToolkit.Core.dll
Syntax
public class ItemsSourceCollection : IList, ICollection, IList<object>, ICollection<object>, IEnumerable<object>, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged
Constructors
| Improve this Doc View SourceItemsSourceCollection()
Initializes a new, empty ItemsSourceCollection without an ItemsSource.
Declaration
public ItemsSourceCollection()
Properties
| Improve this Doc View SourceCount
Gets the number of elements in this collection or an active ItemsSource which implements IEnumerable. If ItemsSource is set, but does not implement IEnumerable, this returns 1.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
HasEnumerableItemsSource
Gets a value indicating whether the ItemsSource implements the IEnumerable interface.
Declaration
protected bool HasEnumerableItemsSource { get; }
Property Value
Type | Description |
---|---|
Boolean |
Remarks
Note that the non-generic IEnumerable interface is tested by this property.
IsFixedSize
Gets a value indicating whether the collection has a fixed size.
Declaration
public bool IsFixedSize { get; }
Property Value
Type | Description |
---|---|
Boolean |
IsReadOnly
Gets a value indicating whether the collection is currently read-only, meaning that any methods which modify it will throw an exception.
Declaration
public bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
Boolean |
IsSynchronized
Gets a value which indicates whether the collection is synchronized. This is not the case. This returns false.
Declaration
public bool IsSynchronized { get; }
Property Value
Type | Description |
---|---|
Boolean |
IsUsingItemsSource
Gets a value indicating whether the collection is currently based on an items source provided by the ItemsSource property.
Declaration
public bool IsUsingItemsSource { get; }
Property Value
Type | Description |
---|---|
Boolean |
Item[Int32]
Gets the element at the specified index, or sets the item at the specified index within the current collection, if no ItemsSource is set.
Declaration
public object this[int index] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index. |
Property Value
Type | Description |
---|---|
Object | The element at the specified index in the collection, if ItemsSource
is null.
If ItemsSource implements IEnumerable, returns the element
at the specified index from the ItemsSource.
If ItemsSource is set, but does not implement IEnumerable,
this will return the ItemsSource, as long as the |
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException | |
InvalidOperationException | Thrown if an attempt to set this property was made, while the collection had an active ItemsSource. |
ItemsSource
Gets or sets an object from which this collection retrieves its items.
Declaration
public object ItemsSource { get; set; }
Property Value
Type | Description |
---|---|
Object |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if this property is set while the collection contains any items which do not come from another items source. |
SyncRoot
Gets an object which can be used for cross-thread synchronization. Accessing this property while an ItemsSource is set will throw a NotSupportedException.
Declaration
public object SyncRoot { get; }
Property Value
Type | Description |
---|---|
Object |
Exceptions
Type | Condition |
---|---|
NotSupportedException | Thrown when this property is accessed while the ItemsSource is set to a valid value. |
Methods
| Improve this Doc View SourceAdd(Object)
Adds the specified value
to the collection.
Declaration
public int Add(object value)
Parameters
Type | Name | Description |
---|---|---|
Object | value | The value to be added. |
Returns
Type | Description |
---|---|
Int32 | The index, at which the value was added. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the ItemsSource property is set. |
Clear()
Removes all elements from the collection.
Declaration
public void Clear()
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the ItemsSource property is set. |
Contains(Object)
Returns a value indicating whether the specified value
can be found
inside this collection.
Declaration
public bool Contains(object value)
Parameters
Type | Name | Description |
---|---|---|
Object | value | The value to be checked. |
Returns
Type | Description |
---|---|
Boolean | true if either the collection, or an ItemsSource which implements
IEnumerable contains the provided |
CopyTo(Array, Int32)
Copies the elements of this collection to the specified array
.
Declaration
public void CopyTo(Array array, int index)
Parameters
Type | Name | Description |
---|---|---|
Array | array | The destination array. |
Int32 | index | The zero-based index in |
GetElementAt(Int32)
Gets the element at the specified index.
Declaration
public object GetElementAt(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index. |
Returns
Type | Description |
---|---|
Object | The element at the specified index in the collection, if ItemsSource
is null.
If ItemsSource implements IEnumerable, returns the element
at the specified index from the ItemsSource.
If ItemsSource is set, but does not implement IEnumerable,
this will return the ItemsSource, as long as the |
Exceptions
Type | Condition |
---|---|
IndexOutOfRangeException |
GetEnumerator()
Returns an enumerator which can be used to enumerate the collection.
Declaration
public IEnumerator<object> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<Object> | An IEnumerator<T> which can be used to enumerate over the collection. |
IndexOf(Object)
Returns the index of the specified value
within the collection.
Declaration
public int IndexOf(object value)
Parameters
Type | Name | Description |
---|---|---|
Object | value | The value to be found. |
Returns
Type | Description |
---|---|
Int32 | The index of the If nothing was found, returns -1. |
Insert(Int32, Object)
Inserts an element into the collection at the specified index
.
Declaration
public void Insert(int index, object value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index at which the element should be inserted. |
Object | value | The element to be inserted. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the ItemsSource property is set. |
OnCollectionChanged(NotifyCollectionChangedEventArgs)
Called before the CollectionChanged event occurs.
Declaration
protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
NotifyCollectionChangedEventArgs | e | Event data for the event. |
OnPropertyChanged(PropertyChangedEventArgs)
Called before the PropertyChanged event occurs.
Declaration
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
PropertyChangedEventArgs | e | Event data for the event. |
RaiseCollectionChanged(NotifyCollectionChangedEventArgs)
Raises the CollectionChanged event and calls the OnCollectionChanged(NotifyCollectionChangedEventArgs) method afterwards. In addition, the PropertyChanged event is raised for the Count and index-accessor properties.
Declaration
protected void RaiseCollectionChanged(NotifyCollectionChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
NotifyCollectionChangedEventArgs | e | Event data for the event. |
RaisePropertyChanged(PropertyChangedEventArgs)
Raises the PropertyChanged event and calls the OnPropertyChanged(PropertyChangedEventArgs) method afterwards.
Declaration
protected void RaisePropertyChanged(PropertyChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
PropertyChangedEventArgs | e | Event data for the event. |
RaisePropertyChanged(String)
Raises the PropertyChanged event and calls the OnPropertyChanged(PropertyChangedEventArgs) method afterwards.
Declaration
protected void RaisePropertyChanged(string propertyName = "")
Parameters
Type | Name | Description |
---|---|---|
String | propertyName | The name of the changed property. |
Remove(Object)
If found, removes the specified value
from the collection.
Declaration
public bool Remove(object value)
Parameters
Type | Name | Description |
---|---|---|
Object | value | The value to be removed from the collection. |
Returns
Type | Description |
---|---|
Boolean | true if removing the item succeeded; false if not. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the ItemsSource property is set. |
RemoveAt(Int32)
Removes the element at the specified index
from the collection.
Declaration
public void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The element's index. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if the ItemsSource property is set. |
Events
| Improve this Doc View SourceCollectionChanged
Occurs when either the internal collection or the ItemsSource changes. The ItemsSource must implement INotifyCollectionChanged for this event to work.
Declaration
public event NotifyCollectionChangedEventHandler CollectionChanged
Event Type
Type | Description |
---|---|
NotifyCollectionChangedEventHandler |
PropertyChanged
Occurs when a property value changes.
Declaration
public event PropertyChangedEventHandler PropertyChanged
Event Type
Type | Description |
---|---|
PropertyChangedEventHandler |