ResourceMap Class

Une collection de ressources associées, généralement pour un package d'application particulier, ou un fichier de ressources pour un package particulier.

Syntaxe


var resourceMap = resourceMap.getSubtree();
var resourceMap = resourceManager.mainResourceMap;
var resourceMap = resourceMapMapView.lookup();

Attributs

[MarshalingBehavior(Agile)]
[Version(0x06020000)]

Membres

ResourceMapClasse possède ces types de membres :

Méthodes

The ResourceMap Classe a les méthodes suivantes. Avec C#, Visual Basic et C++, elle hérite également des méthodes de Object Classe.

MéthodeDescription
ContainsKey [C#, VB]Returns a value that indicates whether a specified key exists in the ResourceMap.
First [C++, JavaScript]Returns an iterator to enumerate the items in the map.
GetSubtree [C++, JavaScript]Returns a ResourceMap that represents a subtree of another ResourceMap, typically used to access a particular resource file within an app package.
GetValue(String) [C++, JavaScript]Returns the most appropriate candidate for a resource that is specified by a resource identifier for the default context.
GetValue(String, ResourceContext) [C++, JavaScript]Returns the most appropriate candidate for a resource that is specified by a resource identifier for the supplied context.
HasKey [C++, JavaScript]Determines whether the map can retrieve a resource with the specified resource identifier.
Lookup [C++, JavaScript]Returns the NamedResource at the specified resource identifier in the map.
Split [C++, JavaScript]Splits the map view into two views.
TryGetValue [C#, VB]Returns a value that indicates whether a specified key exists in the ResourceMap. If an item with that key exists, the item is retrieved as an out parameter.

 

Propriétés

Le ResourceMapClasse a les propriétés suivantes.

PropriétéType d'accèsDescription

Count [C#, VB]

En lecture seuleGets the number of elements contained in the collection.

Item [C#, VB]

En lecture seuleGets or sets the element value at the specified key index.

Keys [C#, VB]

En lecture seuleGets an ICollection object containing the keys of the ResourceMap.

Size [C++, JavaScript]

En lecture seuleGets the number of resources in the map.

Uri

En lecture seuleGets a URI that can be used to refer to this ResourceMap.

Values [C#, VB]

En lecture seuleGets an ICollection object containing the values of the ResourceMap .

 

Remarques

Liste des membres de la collection

En JavaScript, ResourceMap prend en charge l'utilisation d'un index pour accéder aux éléments.

Exemples

Cet exemple est basé sur le scénario 13 de l'Exemple de ressources et de localisation d'application. Pour obtenir la solution complète, consultez l'exemple.


// Create a ResourceContext.
var resourceContext = new Windows.ApplicationModel.Resources.Core.ResourceContext();

// Set the specific context for lookup of resources.
var qualifierValues = resourceContext.qualifierValues;
qualifierValues["language"] = "en-US";
qualifierValues["contrast"] = "standard";
qualifierValues["scale"] = "140";
qualifierValues["homeregion"] = "021"; // Northern America

// Resources actually reside within Scenario13 Resource Map.
var resourceIds = [
    '/Scenario13/languageOnly',
    '/Scenario13/scaleOnly',
    '/Scenario13/contrastOnly',
    '/Scenario13/homeregionOnly',
    '/Scenario13/multiDimensional',
];

var output = { str: "" };
resourceIds.forEach(function (resourceId) {
    renderNamedResource(resourceId, resourceContext, output);
});

function renderNamedResource(resourceId, resourceContext, output) {
    output.str += "Resource ID " + resourceId + ":\n";
    // Lookup the resource in the mainResourceMap (the one for this package).
    var namedResource = Windows.ApplicationModel.Resources.Core.ResourceManager.current.mainResourceMap.lookup(resourceId);

    // Return a ResourceCandidateVectorView of all possible resources candidates
    // resolved against the context in order of appropriateness.
    var resourceCandidates = namedResource.resolveAll(resourceContext);

    resourceCandidates.forEach(function (candidate, index) {
        renderCandidate(candidate, index, output);
    });
    output.str += "\n";
}

function renderCandidate(candidate, index, output) {
    // Get all the various qualifiers for the candidate (such as language, scale, contrast).
    candidate.qualifiers.forEach(function (qualifier) {
        output.str += "qualifierName: " + qualifier.qualifierName + "\n";
        output.str += "qualifierValue: " + qualifier.qualifierValue + "\n";
        output.str += "isDefault: ";
        output.str += (qualifier.isDefault) ? "true\n" : "false\n";
        output.str += "isMatch: ";
        output.str += (qualifier.isMatch) ? "true\n" : "false\n";
        output.str += "score: " + qualifier.score + "\n";
        output.str += "\n";
    });
}

Conditions requises

Client minimal pris en charge

Windows 8 [Applications Windows Store uniquement]

Serveur minimal pris en charge

Windows Server 2012 [Applications Windows Store uniquement]

Espace de noms

Windows.ApplicationModel.Resources.Core
Windows::ApplicationModel::Resources::Core [C++]

Métadonnées

Windows.winmd

Voir aussi

Exemple de ressources et de localisation d'application

 

 

Afficher:
© 2014 Microsoft