Show / Hide Table of Contents

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.

Inheritance
Object
ItemsSourceCollection
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 Source

ItemsSourceCollection()

Initializes a new, empty ItemsSourceCollection without an ItemsSource.

Declaration
public ItemsSourceCollection()

Properties

| Improve this Doc View Source

Count

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
| Improve this Doc View Source

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.

| Improve this Doc View Source

IsFixedSize

Gets a value indicating whether the collection has a fixed size.

Declaration
public bool IsFixedSize { get; }
Property Value
Type Description
Boolean
| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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
| Improve this Doc View Source

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 index is 0.

Exceptions
Type Condition
IndexOutOfRangeException
InvalidOperationException

Thrown if an attempt to set this property was made, while the collection had an active ItemsSource.

| Improve this Doc View Source

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.

| Improve this Doc View 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 Source

Add(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.

| Improve this Doc View Source

Clear()

Removes all elements from the collection.

Declaration
public void Clear()
Exceptions
Type Condition
InvalidOperationException

Thrown if the ItemsSource property is set.

| Improve this Doc View Source

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 value. If ItemsSource does not implement IEnumerable, this returns a value indicating whether it equals the specified value.

| Improve this Doc View Source

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 array from which copying starts.

| Improve this Doc View Source

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 index is 0.

Exceptions
Type Condition
IndexOutOfRangeException
| Improve this Doc View Source

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.

| Improve this Doc View Source

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 value within the collection or the ItemsSource, if the latter implements IEnumerable. If ItemsSource is set, but does not implement IEnumerable, this method compares the ItemsSource object to value and returns 0, if they are equal.

If nothing was found, returns -1.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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 Source

CollectionChanged

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
| Improve this Doc View Source

PropertyChanged

Occurs when a property value changes.

Declaration
public event PropertyChangedEventHandler PropertyChanged
Event Type
Type Description
PropertyChangedEventHandler

Extension Methods

EnumerableExtensions.ElementAfter<T>(IEnumerable<T>, Int32)
EnumerableExtensions.ElementAfterOrDefault<T>(IEnumerable<T>, Int32)
EnumerableExtensions.ElementBefore<T>(IEnumerable<T>, Int32)
EnumerableExtensions.ElementBeforeOrDefault<T>(IEnumerable<T>, Int32)
EnumerableExtensions.IndexOf<T>(IEnumerable<T>, T)
EnumerableExtensions.AddRange<T>(ICollection<T>, IEnumerable<T>)
EnumerableExtensions.RemoveAll<T>(IList<T>, Func<T, Boolean>)

See Also

ItemsSource
  • Improve this Doc
  • View Source
Back to top Copyright © 2018 Celestial.UIToolkit - Impressum