Partager via


XRObservableCollection<ItemType> (Compact 2013)

3/28/2014

This C++ template class represents a data source collection that sends notifications when the collection changes and enables you to create an object instance which has functionality that resembles the Component Object Model (COM).

Syntax

template<typename ItemType>
class XRObservableCollection : public XRValueCollectionT<IXRList, ItemType>, public IXRNotifyCollectionChanged 

Inheritance Hierarchy

XRValueCollectionT<IFace,ItemType>

     XRObservableCollection

Template Parameter

  • ItemType
    The class type for items in the collection.

Members

The following tables list any methods and fields that belong to this class.

Method

Description

XRObservableCollection.ClearItemsImpl

Removes all items from the collection and invokes XRObservableCollection.OnCollectionChanged(XRCollectionChangedCustomEventArgs *) to send an event notification that the collection has changed.

XRObservableCollection.CreateInstance(XRObservableCollection * *)

Returns an XRObservableCollection<ItemType> object instance that also supports functionality that resembles the Component Object Model (COM) and exposes interfaces defined in the interface map to callers of XRObject.QueryInterface(const IID&,void * *).

XRObservableCollection.GetCollectionChangedEvent(IXRCustomEvent<XRCollectionChangedCustomEventArgs, IXRNotifyCollectionChanged> * *)

Obtains the CollectionChanged event for the data source collection.

XRObservableCollection.InsertItemImpl(int,XRValue *)

Implements collection operations that add items to the data source collection and invokes XRObservableCollection.OnCollectionChanged(XRCollectionChangedCustomEventArgs *) to send an event notification that the collection has changed.

XRObservableCollection.OnCollectionChanged(XRCollectionChangedCustomEventArgs *)

Raises the CollectionChanged event for the data source collection.

XRObservableCollection.RemoveItemImpl(int)

Implements collection operations for removing items from the data source collection and invokes XRObservableCollection.OnCollectionChanged(XRCollectionChangedCustomEventArgs *) to send an event notification that the collection has changed.

XRObservableCollection.SetItemImpl(int,XRValue *)

Implements the collection operations for updating objects in the data source collection and invokes XRObservableCollection.OnCollectionChanged(XRCollectionChangedCustomEventArgs *) to send an event notification that the collection has changed.

Fields

Fields

Description

m_IsBusy

Indicates whether the collection is currently being updated. Its value is true when the calling stack is currently in a CollectionChanged event handler.

m_pCollectionChangedEvent

The CollectionChanged event of type IXRCustomEvent that methods in this class raise to indicate that the collection has changed.

Thread Safety

Members of this class are not thread safe when you add, remove, update, or clear the objects in the collection. While you are updating objects with new data from the data provider, implement single-threading and block other operations until the update is finished.

Remarks

To set an XRObservableCollection<ItemType> object instance as the data context for an IXRItemsControl, call IXRFrameworkElement::SetDataContext.

XRObservableCollection<ItemType> implements an interface map. The interface map defines which interface pointers you can request for an XRObservableCollection<ItemType> object instance when you call XRObject.QueryInterface(const IID&,void * *). The interface map includes IXRNotifyCollectionChanged, which has a method that obtains the CollectionChanged event of type IXRCustomEvent. You can attach an event handler to the CollectionChanged event to provide custom handling of changes in the data source collection.

The following example code shows the interface map for XRObservableCollection<ItemType>.

Important

For readability, the following code example does not contain security checking or error handling. Do not use the following code in a production environment.

BEGIN_QI_MAP()
        QI_MAP_INTERFACE(IXRNotifyCollectionChanged)
        QI_MAP_CHAIN(XRValueCollectionT)
END_QI_MAP()

To obtain an instance of the collection object, call XRObservableCollection.CreateInstance(XRObservableCollection * *).

Requirements

Header

XRCollection.h

See Also

Reference

Classes for Populating UI Elements with Data