Share via


DependencyObjectCollection Class

Definition

Implements a practical collection class that can contain DependencyObject items.

/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class DependencyObjectCollection : DependencyObject, IIterable<DependencyObject>, IObservableVector<DependencyObject>, IVector<DependencyObject>
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class DependencyObjectCollection : DependencyObject, IEnumerable<DependencyObject>, IList<DependencyObject>, IObservableVector<DependencyObject>
Public Class DependencyObjectCollection
Inherits DependencyObject
Implements IEnumerable(Of DependencyObject), IList(Of DependencyObject), IObservableVector(Of DependencyObject)
Inheritance
Object IInspectable DependencyObject DependencyObjectCollection
Attributes
Implements

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Remarks

The purpose of the DependencyObjectCollection class is mainly to support the tooling and portability of behaviors. Behaviors are a technique for defining certain basic interactions of a UI element entirely in XAML, without requiring an event handler and code-behind.

If you're interested in implementing a business object class that supports collection-changed notifications you should use ObservableCollection or one of the interface patterns that supports changed events. For more info see Data binding in depth.

Enumerating the collection in C# or Microsoft Visual Basic

A DependencyObjectCollection is enumerable, so you can use language-specific syntax such as foreach in C# to enumerate the items in the collection. The compiler does the type-casting for you and you won't need to cast to IEnumerable<DependencyObject> explicitly. If you do need to cast explicitly, for example if you want to call GetEnumerator, cast to IEnumerable<T> with a DependencyObject constraint.

Constructors

DependencyObjectCollection()

Initializes a new instance of the DependencyObjectCollection class.

Properties

Dispatcher

Gets the CoreDispatcher that this object is associated with. The CoreDispatcher represents a facility that can access the DependencyObject on the UI thread even if the code is initiated by a non-UI thread.

(Inherited from DependencyObject)
Size

Gets the size (count) of the collection.

Methods

Append(DependencyObject)

Adds a new item to the collection.

Clear()

Removes all items from the collection.

ClearValue(DependencyProperty)

Clears the local value of a dependency property.

(Inherited from DependencyObject)
First()

Returns the iterator for iteration over the items in the collection.

GetAnimationBaseValue(DependencyProperty)

Returns any base value established for a dependency property, which would apply in cases where an animation is not active.

(Inherited from DependencyObject)
GetAt(UInt32)

Returns the DependencyObject located at the specified index.

GetMany(UInt32, DependencyObject[])

Retrieves multiple elements in a single pass through the iterator.

GetValue(DependencyProperty)

Returns the current effective value of a dependency property from a DependencyObject.

(Inherited from DependencyObject)
GetView()

Gets an immutable view into the collection.

IndexOf(DependencyObject, UInt32)

Retrieves the index of the specified item.

InsertAt(UInt32, DependencyObject)

Inserts the specified item at the specified index.

ReadLocalValue(DependencyProperty)

Returns the local value of a dependency property, if a local value is set.

(Inherited from DependencyObject)
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback)

Registers a notification function for listening to changes to a specific DependencyProperty on this DependencyObject instance.

(Inherited from DependencyObject)
RemoveAt(UInt32)

Removes the item at the specified index.

RemoveAtEnd()

Removes the last item in the collection.

ReplaceAll(DependencyObject[])

Initially clears the collection, then inserts the provided array as new items.

SetAt(UInt32, DependencyObject)

Sets the value at the specified index to the DependencyObject value specified.

SetValue(DependencyProperty, Object)

Sets the local value of a dependency property on a DependencyObject.

(Inherited from DependencyObject)
UnregisterPropertyChangedCallback(DependencyProperty, Int64)

Cancels a change notification that was previously registered by calling RegisterPropertyChangedCallback.

(Inherited from DependencyObject)

Events

VectorChanged

Occurs when the contents of the collection changes.

Applies to

See also