DependencyObjectCollection Class


Implements a practical collection class that can contain DependencyObject items.

/// [Windows.Foundation.Metadata.Composable(Microsoft.UI.Xaml.IDependencyObjectCollectionFactory, Windows.Foundation.Metadata.CompositionType.Public, 65536, "Microsoft.UI.Xaml.WinUIContract")]
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.WebHostHidden]
class DependencyObjectCollection : DependencyObject, IIterable<DependencyObject>, IObservableVector<DependencyObject>, IVector<DependencyObject>
[Windows.Foundation.Metadata.Composable(typeof(Microsoft.UI.Xaml.IDependencyObjectCollectionFactory), Windows.Foundation.Metadata.CompositionType.Public, 65536, "Microsoft.UI.Xaml.WinUIContract")]
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
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)
Windows.Foundation.Metadata.ComposableAttribute Windows.Foundation.Metadata.ContractVersionAttribute Windows.Foundation.Metadata.MarshalingBehaviorAttribute Windows.Foundation.Metadata.ThreadingAttribute Windows.Foundation.Metadata.WebHostHiddenAttribute
IEnumerable<DependencyObject> IEnumerable<T> IList<DependencyObject> IList<T> Windows.Foundation.Collections.IObservableVector<DependencyObject>


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 with a DependencyObject constraint.



Initializes a new instance of the DependencyObjectCollection class.



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)

Gets the DispatcherQueue that this object is associated with. The DispatcherQueue 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)

Gets the size (count) of the collection.



Adds a new item to the collection.


Removes all items from the collection.


Clears the local value of a dependency property.

(Inherited from DependencyObject)

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


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

(Inherited from DependencyObject)

Returns the DependencyObject located at the specified index.

GetMany(UInt32, DependencyObject[])

Retrieves multiple elements in a single pass through the iterator.


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

(Inherited from DependencyObject)

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.


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)

Removes the item at the specified index.


Removes the last item in the collection.


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)



Occurs when the contents of the collection changes.

Applies to

See also