NamedResource
NamedResource
NamedResource
NamedResource
Class
Definition
Represents a single logical, named resource, such as a string resource named 'Header1'.
public : sealed class NamedResource : INamedResourcepublic sealed class NamedResource : INamedResourcePublic NotInheritable Class NamedResource Implements INamedResource// You can use this class in JavaScript.
- Attributes
| Device family |
Windows 10 (introduced v10.0.10240.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced v1)
|
Examples
This example is based on scenario 13 of the Application resources and localization sample. See the sample for the more complete solution.
// 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";
});
}
Properties
Candidates Candidates Candidates Candidates
Gets all possible candidate values for this named resource.
public : IVectorView<ResourceCandidate> Candidates { get; }public IReadOnlyList<ResourceCandidate> Candidates { get; }Public ReadOnly Property Candidates As IReadOnlyList<ResourceCandidate>// You can use this property in JavaScript.
- Value
- IVectorView<ResourceCandidate> IReadOnlyList<ResourceCandidate> IReadOnlyList<ResourceCandidate> IReadOnlyList<ResourceCandidate>
A set of ResourceCandidate objects, each of which describes one possible value for this named resource and the qualifiers under which it applies.
Uri Uri Uri Uri
Gets a URI that can be used to refer to this named resource.
public : Uri Uri { get; }public Uri Uri { get; }Public ReadOnly Property Uri As Uri// You can use this property in JavaScript.
- Value
- Uri Uri Uri Uri
A URI that can be used to refer to this named resource. See URI schemes for information on identifying resources.
- See Also
Methods
Resolve() Resolve() Resolve() Resolve()
Note
Resolve may be altered or unavailable for releases after Windows 8.1. Instead, use Resolve(ResourceContext).
Resolves this NamedResource object against the default context and returns the most appropriate candidate.
public : ResourceCandidate Resolve()public ResourceCandidate Resolve()Public Function Resolve() As ResourceCandidate// You can use this method in JavaScript.
The most appropriate candidate for the default context.
- See Also
Resolve(ResourceContext) Resolve(ResourceContext) Resolve(ResourceContext) Resolve(ResourceContext)
Resolves this NamedResource object against a supplied context and returns the most appropriate candidate.
public : ResourceCandidate Resolve(ResourceContext resourceContext)public ResourceCandidate Resolve(ResourceContext resourceContext)Public Function Resolve(resourceContext As ResourceContext) As ResourceCandidate// You can use this method in JavaScript.
- resourceContext
- ResourceContext ResourceContext ResourceContext ResourceContext
The context against which the NamedResource should be resolved.
The most appropriate candidate for the specified context.
Remarks
The resource management system for Windows Store app supports the tailoring of resources for scale. Starting in Windows 8.1, different views owned by an app are able to display simultaneously on different display devices that may use different scales. In this way, scale is a per-view characteristic.
Since the Resolve method selects the best candidate for a NamedResource in relation to a runtime context, and since the scale qualifier of a ResourceContext depends on the associated view, the Resolve should always be called passing a ResourceContext object obtained from the view in which the resource will be used.
See the ResourceContext.GetForCurrentView method.
- See Also
ResolveAll() ResolveAll() ResolveAll() ResolveAll()
Note
ResolveAll may be altered or unavailable for releases after Windows 8.1. Instead, use ResolveAll(ResourceContext).
Resolves this NamedResource object against the default context and returns a list of all possible candidates in preference order.
public : IVectorView<ResourceCandidate> ResolveAll()public IReadOnlyList<ResourceCandidate> ResolveAll()Public Function ResolveAll() As IReadOnlyList( Of ResourceCandidate )// You can use this method in JavaScript.
A list of ResourceCandidate objects, in order of preference. The object in first position in the list is the most appropriate candidate for the corresponding context, and the object in last position is the least appropriate.
- See Also
ResolveAll(ResourceContext) ResolveAll(ResourceContext) ResolveAll(ResourceContext) ResolveAll(ResourceContext)
Resolves this NamedResource object against a supplied context and returns a list of all possible candidates in preference order.
public : IVectorView<ResourceCandidate> ResolveAll(ResourceContext resourceContext)public IReadOnlyList<ResourceCandidate> ResolveAll(ResourceContext resourceContext)Public Function ResolveAll(resourceContext As ResourceContext) As IReadOnlyList( Of ResourceCandidate )// You can use this method in JavaScript.
- resourceContext
- ResourceContext ResourceContext ResourceContext ResourceContext
The context against which the NamedResource should be resolved.
A list of ResourceCandidate objects, in order of preference. The object in first position in the list is the most appropriate candidate for the corresponding context, and the object in last position is the least appropriate.
Remarks
The resource management system for Windows Store app supports the tailoring of resources for scale. Starting in Windows 8.1, different views owned by an app are able to display simultaneously on different display devices that may use different scales. In this way, scale is a per-view characteristic.
Since the ResolveAll method returns all candidates for a NamedResource in relation to a runtime context, and since the scale qualifier of a ResourceContext depends on the associated view, the ResolveAll should always be called passing a ResourceContext object obtained from the view in which the resource will be used.
See the ResourceContext.GetForCurrentView method.
- See Also