Share via


ResourceMap Class

Definition

A collection of related resources, typically either for a particular app package, or a resource file for a particular package.

public ref class ResourceMap sealed : IIterable<IKeyValuePair<Platform::String ^, NamedResource ^> ^>, IMapView<Platform::String ^, NamedResource ^>
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class ResourceMap final : IIterable<IKeyValuePair<winrt::hstring, NamedResource const&>>, IMapView<winrt::hstring, NamedResource const&>
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class ResourceMap : IEnumerable<KeyValuePair<string,NamedResource>>, IReadOnlyDictionary<string,NamedResource>
Public NotInheritable Class ResourceMap
Implements IEnumerable(Of KeyValuePair(Of String, NamedResource)), IReadOnlyDictionary(Of String, NamedResource)
Inheritance
Object Platform::Object IInspectable ResourceMap
Attributes
Implements

Windows requirements

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

Examples

This example is based on scenario 8 of the Application resources and localization sample. See the sample for the complete solution.

private void ShowText()
{
    ResourceContext defaultContextForCurrentView = ResourceContext.GetForCurrentView();
    ResourceMap stringResourcesResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("Resources");
    Scenario8MessageTextBlock.Text = stringResourcesResourceMap.GetValue("string1", defaultContextForCurrentView).ValueAsString;
}
void Scenario8::ShowText()
{
    ResourceContext^ defaultContextForCurrentView = ResourceContext::GetForCurrentView();
    auto resourceStringMap = ResourceManager::Current->MainResourceMap->GetSubtree("Resources");
    Scenario8MessageTextBlock->Text = resourceStringMap->GetValue("string1", defaultContextForCurrentView)->ValueAsString;
}

Remarks

Resource identifier syntax

Many methods of this class use resource identifiers as parameters. The resource identifier is treated as a Uniform Resource Identifier (URI) fragment, subject to Uniform Resource Identifier (URI) semantics. For example, GetValue("Caption%20") is treated as GetValue("Caption ").

Do not use "?" or "#" in resource identifiers, because they terminate the resource path evaluation. For example, "MyResource?3" is treated as "MyResource".

Properties

Size

Gets the number of resources in the map.

Uri

Gets a URI that can be used to refer to this ResourceMap.

Methods

First()

Returns an iterator to enumerate the items in the map.

GetSubtree(String)

Returns a ResourceMap that represents a part of another ResourceMap, typically used to access a particular resource file within an app package.

This method finds subtree, ancestor, sibling and cousin maps to this resource map, as well as top-level maps. It returns the resource map represented by a given resource map identifier, relative to this resource map. This method is typically used to make simpler references to a particular subset of resources, such as a single resource file, or a directory of files.

GetValue(String, ResourceContext)

Returns the most appropriate candidate for a resource that is specified by a resource identifier for the supplied context.

GetValue(String)

Note

GetValue(String) may be altered or unavailable for releases after Windows 8.1. Instead, use GetValue(String, ResourceContext).

Returns the most appropriate candidate for a resource that is specified by a resource identifier within the default context.

HasKey(String)

Determines whether the map can retrieve a resource with the specified resource identifier.

Lookup(String)

Returns the NamedResource at the specified resource identifier in the map.

Split(IMapView<String,NamedResource>, IMapView<String,NamedResource>)

Splits the map view into two views.

Applies to

See also