Partager via


TPropertyBag<Derived> (Compact 2013)

3/28/2014

This C++ template class manages access to properties in a property bag for a data source object and provides access to the PropertyChanged event for the property bag.

Syntax

template<typename Derived>
class __declspec(novtable) TPropertyBag : public iXRPropertyBagBinding

Inheritance Hierarchy

iXRPropertyBagBinding

     TPropertyBag<Derived>

Template Parameters

  • Derived
    The name of the class type for the data source object that implements TPropertyBag<Derived>.

Members

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

Methods

Methods

Description

TPropertyBag.BeginRegisterProperties

Ensures mutually exclusive access to data in the property bag before you start registering data source properties.

TPropertyBag.CreateInstance(Derived * *)

Returns an instance of the data source object that implements the TPropertyBag<Derived> interface and that supports functionality that resembles the Component Object Model (COM) and exposes interfaces defined in the TPropertyBag<Derived> interface map.

TPropertyBag.EndRegisterProperties

Finishes the process of registering data source properties in the property bag.

TPropertyBag.GetPropertyByName(const ce::wstring&)

Returns an iXRPropertyBinding-derived object that is associated with the specified property name.

TPropertyBag.GetPropertyChangedEvent(IXRCustomEvent<XRPropertyChangedCustomEventArgs, IXRPropertyBag>**)

Obtains the PropertyChanged event that a property raises when its value changes.

TPropertyBag.GetPropertyName(iXRPropertyBinding *)

Returns the name of the property that is represented by the specified iXRPropertyBinding object.

TPropertyBag.GetValue(const WCHAR *,XRValue *)

Obtains the current value of a data source property in the property bag.

TPropertyBag.RegisterBoundProperty(const ce.wstring&,iXRPropertyBinding &)

Registers a data source property with the property bag.

TPropertyBag.SetValue(const WCHAR *,XRValue *)

Sets a new value for a data source property in the property bag.

Fields

Fields

Description

m_pPropertyChangedEvent

The PropertyChanged event.

m_PropertiesMap

The metadata table that stores all property names.

m_ValueTable

The value table of all properties. Values are stored in the order that you registered them.

s_AddProperties

A Boolean value that indicates whether m_PropertiesMap is initialized.

s_InitializationCriticalSection

A critical section object that is used to initialize m_PropertiesMap with added thread-safety.

s_PropertyNames

A vector object that stores property name strings for registered properties.

Thread Safety

The TPropertyBag.RegisterBoundProperty(const ce.wstring&,iXRPropertyBinding &) method is thread-safe after you call TPropertyBag.BeginRegisterProperties. When you are finished with registering properties, you must call TPropertyBag.EndRegisterProperties. Other methods on this interface are not thread-safe when you are registering new properties or updating property values. While you are registering properties or updating property values, implement single-threading and block other operations until the task is finished. For example, use XRAutoCriticalSection.

Remarks

TPropertyBag<Derived> is a property bag, in which an object stores its properties, and is a helper extension for IXRPropertyBag.

To set a data source object that implements TPropertyBag<Derived> as the data context for a UI element, call IXRFrameworkElement::SetDataContext. Then, to bind property data to a UI element, either call IXRFrameworkElement::SetBinding or use a Binding Markup Extension in Microsoft Silverlight 3 XAML.

In contrast to its superinterface IXRPropertyBag, TPropertyBag<Derived> provides an IXRCustomEvent object, which you access by calling TPropertyBag.GetPropertyChangedEvent(IXRCustomEvent<XRPropertyChangedCustomEventArgs, IXRPropertyBag>**).

The functionality in this class differs from Microsoft Silverlight 3. XAML for Windows Embedded does not support C++ equivalent classes for the System.Reflection namespace in Microsoft Silverlight 3 for invoking programming elements by name. Instead, you can use this class to resolve a data source property by name, instead of by a C++ object instance.

To resolve properties by name, you must first register the properties with the property bag by calling TPropertyBag.RegisterBoundProperty(const ce.wstring&,iXRPropertyBinding &).

TPropertyBag<Derived> implements an interface map so that you can access its methods through interfaces obtained by using IUnknown::QueryInterface. TPropertyBag<Derived> defines the interface map by using the BEGIN_QI_MAP and END_QI_MAP macros.

Make sure that your custom data source object inherits from TPropertyBag<Derived>. The data source object must define a set of iXRPropertyBinding derived objects that each represent properties whose values are displayed in data-bound elements in the UI.

When you use TPropertyBag <Derived> with a NULL value, a debug break occurs as a warning that your code might later fail. To determine the source of your error, check the HRESULT that was returned when you set TPropertyBag <Derived>.

Obtaining a Pointer

To obtain a TPropertyBag<Derived> pointer on a data source object of type Derived, call TPropertyBag.CreateInstance(Derived * *). To obtain a TPropertyBag<Derived> pointer on a data source object in a data source collection, call XRValueCollectionT.GetItem(int,ItemType *).

Example

The following code example shows the interface mapping for TPropertyBag<Derived>.

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.

template<typename Derived>
class __declspec(novtable) TPropertyBag : public iXRPropertyBagBinding
{
    BEGIN_QI_MAP()
        QI_MAP_INTERFACE(Derived)
        QI_MAP_INTERFACE(TPropertyBag)
        QI_MAP_INTERFACE(IXRPropertyBag)
    END_QI_MAP()

Requirements

Header

XRPropertyBag.h

See Also

Reference

Classes for Populating UI Elements with Data
TBoundProperty<PropertyType>
TBoundProperty<BSTR>
TBoundPointerProperty<PropertyType>