次の方法で共有


IXRResourceDictionary (Compact 2013)

3/28/2014

This class provides a dictionary that contains keyed resources used by components of a XAML for Windows Embedded based application.

Syntax

class IXRResourceDictionary : public IXRDependencyObject

Inheritance Hierarchy

IXRDependencyObject

     IXRResourceDictionary

Methods

Method

Description

IXRResourceDictionary::Add

Adds an item to the resource dictionary.

IXRResourceDictionary::Clear

Removes all items from this resource dictionary.

IXRResourceDictionary::Contains

Determines whether this resource dictionary contains the item that has the specified key name.

IXRResourceDictionary::GetCount

Retrieves the number of items that are contained in the resource dictionary.

IXRResourceDictionary::GetItem

Retrieves the item with the specified key name.

IXRResourceDictionary::Remove

Removes a specific item from the resource dictionary.

Thread Safety

Members of this class are thread safe if you previously called IXRApplication::CreateHostFromXaml and supplied it with an XRWindowCreateParams structure that has AllowsMultipleThreadAccess set to true.

Remarks

A resource dictionary is a keyed dictionary of objects that can be defined both in XAML and in C++ code. XAML is the most common usage, particularly for initially defining objects in a resource dictionary. Resource dictionaries can exist at several positions in an application structure, including as application-scope resources that belong to IXRApplication, as immediate resources for any object that inherits from IXRFrameworkElement, or as XAML files that are kept separate and unloaded in the application structure for later run-time use.

Resource dictionaries commonly support two major scenarios: defining templates for controls and defining storyboards for animated properties. For example, an IXRControlTemplate object can be defined as a resource if it is included as an item in a resource dictionary belonging to an object. Or, an IXRStoryboard object can be defined as a resource of a specific object if it is included in the resource dictionary for an object.

The IXRFrameworkElement::GetResources method uses the IXRResourceDictionary object type. To obtain a pointer to an IXRResourceDictionary object for a UI element, call the inherited method IXRFrameworkElement::GetResources for an object derived from IXRFrameworkElement. Then, use the methods of IXRResourceDictionary to add items, delete items, or clear the complete collection. These items will usually be either IXRStoryboard objects or IXRControlTemplate objects.

The IXRApplication::GetResourceDictionary method also uses the IXRResourceDictionary object type. To obtain a pointer to an IXRResourceDictionary object for the application, call the method IXRApplication::GetResourceDictionary.

When you create a class instance, use an IXRResourceDictionaryPtr smart pointer instead of a raw interface pointer. For more information, see XRPtr<Interface>.

You can define a resource dictionary in Microsoft Silverlight 3 XAML. For information about the differences between XAML in XAML for Windows Embedded and Silverlight 3, see Differences Between Microsoft Silverlight 3 and XAML for Windows Embedded. For more information about how to define this element in the source XAML for your application, see the ResourceDictionary Class on MSDN.

The items contained in IXRResourceDictionary must each have a key defined. You can define a key in the source XAML for your application by providing a value for the x:Key attribute on the object element that is added as <ResourceDictionary> content. Or, you can define a key when you call IXRResourceDictionary::Add. If x:Key is not specified, the x:Name is used as the key.

For more information about using these attributes in Microsoft Silverlight 3 XAML, see "Keys and Resources" and "Referencing Resources from XAML" in the Resource Dictionaries topic on MSDN.

If an x:Name or x:Key was defined in source XAML, you can locate an object in a resource dictionary from C++ code after the XAML is parsed into an object tree. To do this, call the method IXRResourceDictionary::GetItem.

.NET Framework Equivalent

System.Windows.ResourceDictionary

Requirements

Header

XamlRuntime.h

sysgen

SYSGEN_XAML_RUNTIME

See Also

Reference

Classes for Collection Management
IXRApplication::LoadResourceDictionary
IXRApplication::GetResourceDictionary
IXRFrameworkElement::GetResources