ResourceMap Class


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)]
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)
Object IInspectable ResourceMap

Windows requirements

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


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

private void Scenario10Button_Show_Click(object sender, RoutedEventArgs e)
    Button b = sender as Button;
    if (b != null)
        // Use a cloned context for this scenario so that qualifier values set
        // in this scenario don't impact behavior in other scenarios that
        // use a default context for the view (crossover effects between
        // the scenarios will not be expected).
        var context = ResourceContext.GetForCurrentView().Clone();

        var selectedLanguage = Scenario10ComboBox_Language.SelectedValue;
        var selectedScale = Scenario10ComboBox_Scale.SelectedValue;
        var selectedContrast = Scenario10ComboBox_Contrast.SelectedValue;
        var selectedHomeRegion = Scenario10ComboBox_HomeRegion.SelectedValue;

        if (selectedLanguage != null)
            context.QualifierValues["language"] = selectedLanguage.ToString();
        if (selectedScale != null)
            context.QualifierValues["scale"] = selectedScale.ToString();
        if (selectedContrast != null)
            context.QualifierValues["contrast"] = selectedContrast.ToString();
        if (selectedHomeRegion != null)
            context.QualifierValues["homeregion"] = selectedHomeRegion.ToString();
        Scenario10_SearchMultipleResourceIds(context, new string[] { "LanguageOnly", "ScaleOnly", "ContrastOnly", "HomeRegionOnly", "MultiDimensional" });

void Scenario10_SearchMultipleResourceIds(ResourceContext context, string[] resourceIds)
    this.Scenario10TextBlock.Text = "";
    var dimensionMap = ResourceManager.Current.MainResourceMap.GetSubtree("dimensions");

    foreach (var id in resourceIds)
        NamedResource namedResource;
        if (dimensionMap.TryGetValue(id, out namedResource))
            var resourceCandidates = namedResource.ResolveAll(context);
            Scenario10_ShowCandidates(id, resourceCandidates);

void Scenario10_ShowCandidates(string resourceId, IReadOnlyList<ResourceCandidate> resourceCandidates)
    // Print 'resourceId', 'found value', 'qualifer info', 'matching condition'
    string outText = "resourceId: dimensions\\" + resourceId + "\r\n";
    int i = 0;
    foreach (var candidate in resourceCandidates)
        var value = candidate.ValueAsString;
        outText += "    Candidate " + i.ToString() + ":" + value + "\r\n";
        int j = 0;
        foreach (var qualifier in candidate.Qualifiers)
            var qualifierName = qualifier.QualifierName;
            var qualifierValue = qualifier.QualifierValue;
            outText += "        Qualifer: " + qualifierName + ": " + qualifierValue + "\r\n";
            outText += "        Matching: IsMatch (" + qualifier.IsMatch.ToString() + ")  " + "IsDefault (" + qualifier.IsDefault.ToString() + ")" + "\r\n";

    this.Scenario10TextBlock.Text += outText + "\r\n";


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".



Gets the number of resources in the map.


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



Returns an iterator to enumerate the items in the map.


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) 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.

GetValue(String, ResourceContext)

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


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


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