NamedResource NamedResource NamedResource NamedResource Class

Represents a single logical, named resource, such as a string resource named 'Header1'.

Syntax

Declaration

public sealed class NamedResourcepublic sealed class NamedResourcePublic NotInheritable Class NamedResourcepublic sealed class NamedResource

Remarks

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 summary

Gets all possible candidate values for this named resource.

Gets a URI that can be used to refer to this named resource.

Methods summary

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.

Resolves this NamedResource object against a supplied context and returns the most appropriate candidate.

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.

Resolves this NamedResource object against a supplied context and returns a list of all possible candidates in preference order.

Properties

  • Candidates
    Candidates
    Candidates
    Candidates

    Gets all possible candidate values for this named resource.

    public IVectorView<ResourceCandidate> Candidates { get; }public IVectorView<ResourceCandidate> Candidates { get; }Public ReadOnly Property Candidates As IVectorView<ResourceCandidate>public IVectorView<ResourceCandidate> Candidates { get; }

    Property Value

    • 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 Uripublic Uri Uri { get; }

    Property Value

    • A URI that can be used to refer to this named resource. See URI schemes for information on identifying resources.

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 ResourceCandidatepublic ResourceCandidate Resolve()

    Returns

  • 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 ResourceCandidatepublic ResourceCandidate Resolve(ResourceContext resourceContext)

    Parameters

    Returns

    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(ResourceContext) 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(ResourceContext) should always be called passing a ResourceContext object obtained from the view in which the resource will be used.

    See the GetForCurrentView() method.

  • 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 IVectorView<ResourceCandidate> ResolveAll()Public Function ResolveAll() As IVectorView( Of ResourceCandidate )public IVectorView<ResourceCandidate> ResolveAll()

    Returns

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

  • 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 IVectorView<ResourceCandidate> ResolveAll(ResourceContext resourceContext)Public Function ResolveAll(resourceContext As ResourceContext) As IVectorView( Of ResourceCandidate )public IVectorView<ResourceCandidate> ResolveAll(ResourceContext resourceContext)

    Parameters

    Returns

    • 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(ResourceContext) 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(ResourceContext) should always be called passing a ResourceContext object obtained from the view in which the resource will be used.

    See the GetForCurrentView() method.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute

Details

Assembly

Windows.ApplicationModel.Resources.Core.dll