ResourceLoader ResourceLoader ResourceLoader ResourceLoader Class

Provides simplified access to app resources such as app UI strings.

Syntax

Declaration

public sealed class ResourceLoaderpublic sealed class ResourceLoaderPublic NotInheritable Class ResourceLoaderpublic sealed class ResourceLoader

Remarks

A ResourceLoader object encapsulates a particular ResourceMap and a ResourceContext, combined in a simple API.

A specific resource map can be specified when the ResourceLoader is obtained; if no resource map is specified, the ResourceLoader will provide access to the "Resources" subtree of the app's main resource map.

In general, resources can be sensitive to scale or other display characteristics. For that reason, resource contexts are generally associated with a specific view. Since a ResourceLoader encapsulates a resource context, this also applies to a ResourceLoader. A ResourceLoader obtained using GetForCurrentView() has a resource context associated with a view in which it was obtained. A view-independent ResourceLoader can also be obtained using GetForViewIndependentUse(String)

  • In : Windows Store app could show their UI on only a single monitor at a time. Frameworks and apps therefore used only a single scale factor at a time, which would change if the app was displayed on a different monitor.
  • Beginning in : Multiple monitors can display multiple Windows Store app at a time, and one app can appear on multiple monitors simultaneously. Frameworks and apps therefore have to deal with multiple scale factors at a time. For Windows 8.1 apps:
  • Obtain the scale factor for the current view by using the DisplayInformation class instead of the deprecated DisplayProperties class.
  • Apps that set explicit width and height of elements should still work fine, other than possibly displaying blurry images.
  • Obtain resources that are not associated with any view by getting a ResourceLoader via GetForViewIndependentUse(String).

See Guidelines for window sizes and scaling to screens and UX guidelines for layout and scaling.

Examples

Use the GetString(String) method to get the string resource identified by "Farewell".

var loader = new Windows.ApplicationModel.Resources.ResourceLoader.getForCurrentView();
var text = loader.getString('Farewell');
var loader = new Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
var text = loader.GetString("Farewell");
Dim loader As New Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView()
Dim Text As String = loader.GetString("Farewell")
auto loader = ref new Windows::ApplicationModel::Resources::ResourceLoader::GetForCurrentView();
String^ text = loader->GetString("Farewell");

Constructors summary

Note

ResourceLoader() may be altered or unavailable for releases after Windows 8.1. Instead, use GetForCurrentView().

Constructs a new ResourceLoader object for the "Resources" subtree of the currently running app's main ResourceMap.

Note

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

Constructs a new ResourceLoader object for the specified ResourceMap.

Methods summary

Gets a ResourceLoader object for the GetSubtree(String) of the currently running app's main ResourceMap. This ResourceLoader uses a default context associated with the current view.

Gets a ResourceLoader object for the specified ResourceMap. This ResourceLoader uses a default context associated with the current view.

Gets a ResourceLoader object for the GetSubtree(String) of the currently running app's main ResourceMap. This ResourceLoader uses a default context that's not associated with any view.

Gets a ResourceLoader object for the specified ResourceMap. This ResourceLoader uses a default context that's not associated with any view.

Returns the most appropriate string value of a resource, specified by resource identifier, for the default ResourceContext of the view in which the ResourceLoader was obtained using GetForCurrentView().

Note

GetStringForReference may be altered or unavailable for releases after Windows 8.1. Instead, use GetStringForUri(Uri).

Returns the most appropriate string value of a resource, specified as a Uri for a resource identifier, for the default ResourceContext of the currently running app.

Returns the most appropriate string value of a resource, specified by a Uniform Resource Identifier (URI) resource identifier, for the default ResourceContext of the currently running app.

Constructors

  • ResourceLoader()
    ResourceLoader()
    ResourceLoader()
    ResourceLoader()
    Note

    ResourceLoader() may be altered or unavailable for releases after Windows 8.1. Instead, use GetForCurrentView().

    Constructs a new ResourceLoader object for the "Resources" subtree of the currently running app's main ResourceMap.

    public ResourceLoader()public New()Public Sub New()public ResourceLoader()

    Remarks

    The empty constructor typically allows access relative to a resource file's named resources (resources.resjson or resources.resw).

    This constructor fails with an exception if the main ResourceMap does not have a "Resources" subtree.

  • ResourceLoader(String)
    ResourceLoader(String)
    ResourceLoader(String)
    ResourceLoader(String)
    Note

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

    Constructs a new ResourceLoader object for the specified ResourceMap.

    public ResourceLoader(String name)public New(String name)Public Sub New(name As String)public ResourceLoader(String name)

    Parameters

    • name
      System.String
      System.String
      System.String
      System.String

      The resource identifier of the ResourceMap that the new resource loader uses for unqualified resource references. It can then retrieve resources relative to those references.

      Note

      The resource identifier is treated as a Uniform Resource Identifier (URI) fragment, subject to Uniform Resource Identifier (URI) semantics. For example, "Caption%20" is treated as "Caption ". Do not use "?" or "#" in resource identifiers, as they terminate the named resource path. For example, "Foo?3" is treated as "Foo".

    Remarks

    This constructor is typically used to access resources relative to a resource file with the specified resource identifier. For example, new ResourceLoader('Errors'); is relative to errors.resjson or errors.resw.

Methods

  • GetForCurrentView()
    GetForCurrentView()
    GetForCurrentView()
    GetForCurrentView()

    Gets a ResourceLoader object for the GetSubtree(String) of the currently running app's main ResourceMap. This ResourceLoader uses a default context associated with the current view.

    public static ResourceLoader GetForCurrentView()public static ResourceLoader GetForCurrentView()Public Static Function GetForCurrentView() As ResourceLoaderpublic static ResourceLoader GetForCurrentView()

    Returns

    Remarks

    This method allows access relative to a resource file named "resources" (resources.resjson or resources.resw). The ResourceLoader that is returned uses a default context associated with the current view.

    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.

    A ResourceLoader has an implicit context that is used when ResourceLoader methods are used to retrieve a resource. Since a ResourceLoader has an implicit context, and since the scale qualifier of contexts is dependent on an associated view, a ResourceLoader must be associated with a particular view.

    Errors

    This method fails with an exception if it is called in a windowless thread, or if the main ResourceMap does not have a "resources" subtree.

  • GetForCurrentView(String)
    GetForCurrentView(String)
    GetForCurrentView(String)
    GetForCurrentView(String)

    Gets a ResourceLoader object for the specified ResourceMap. This ResourceLoader uses a default context associated with the current view.

    public static ResourceLoader GetForCurrentView(String name)public static ResourceLoader GetForCurrentView(String name)Public Static Function GetForCurrentView(name As String) As ResourceLoaderpublic static ResourceLoader GetForCurrentView(String name)

    Parameters

    • name
      System.String
      System.String
      System.String
      System.String

      The resource identifier of the ResourceMap that the new resource loader uses for unqualified resource references. The loader can then retrieve resources relative to those references.

      Note

      The resource identifier is treated as a Uniform Resource Identifier (URI) fragment, subject to Uniform Resource Identifier (URI) semantics. For example, "Caption%20" is treated as "Caption ". Do not use "?" or "#" in resource identifiers, as they terminate the named resource path. For example, "Foo?3" is treated as "Foo".

    Returns

    Remarks

    This method is typically used to access resources relative to a resource file with the specified resource identifier. For example, GetForCurrentView('Errors'); is relative to errors.resjson or errors.resw.

    To construct a resource loader for resources from a library package, a resource reference Uniform Resource Identifier (URI) is used.

    The ResourceLoader that is returned uses a default context associated with the current view.

    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.

    A ResourceLoader has an implicit context that is used when ResourceLoader methods are used to retrieve a resource. Since a ResourceLoader has an implicit context, and since the scale qualifier of contexts is dependent on an associated view, a ResourceLoader must be associated with a particular view.

    Errors

    This method fails with an exception if it is called in a windowless thread, or if the specified ResourceMap cannot be found.

  • GetForViewIndependentUse()
    GetForViewIndependentUse()
    GetForViewIndependentUse()
    GetForViewIndependentUse()

    Gets a ResourceLoader object for the GetSubtree(String) of the currently running app's main ResourceMap. This ResourceLoader uses a default context that's not associated with any view.

    public static ResourceLoader GetForViewIndependentUse()public static ResourceLoader GetForViewIndependentUse()Public Static Function GetForViewIndependentUse() As ResourceLoaderpublic static ResourceLoader GetForViewIndependentUse()

    Returns

  • GetForViewIndependentUse(String)
    GetForViewIndependentUse(String)
    GetForViewIndependentUse(String)
    GetForViewIndependentUse(String)

    Gets a ResourceLoader object for the specified ResourceMap. This ResourceLoader uses a default context that's not associated with any view.

    public static ResourceLoader GetForViewIndependentUse(String name)public static ResourceLoader GetForViewIndependentUse(String name)Public Static Function GetForViewIndependentUse(name As String) As ResourceLoaderpublic static ResourceLoader GetForViewIndependentUse(String name)

    Parameters

    • name
      System.String
      System.String
      System.String
      System.String

      The resource identifier of the ResourceMap that the new resource loader uses for unqualified resource references. The loader can then retrieve resources relative to those references.

      Note

      The resource identifier is treated as a Uniform Resource Identifier (URI) fragment, subject to Uniform Resource Identifier (URI) semantics. For example, "Caption%20" is treated as "Caption ". Do not use "?" or "#" in resource identifiers, as they terminate the named resource path. For example, "Foo?3" is treated as "Foo".

    Returns

  • GetString(String)
    GetString(String)
    GetString(String)
    GetString(String)

    Returns the most appropriate string value of a resource, specified by resource identifier, for the default ResourceContext of the view in which the ResourceLoader was obtained using GetForCurrentView().

    public string GetString(String resource)public string GetString(String resource)Public Function GetString(resource As String) As stringpublic string GetString(String resource)

    Parameters

    • resource
      System.String
      System.String
      System.String
      System.String

      The resource identifier of the resource to be resolved.

      Note

      The resource identifier is treated as a Uniform Resource Identifier (URI) fragment, subject to Uniform Resource Identifier (URI) semantics. For example, getString ("Caption%20") is treated as getString ("Caption "). Do not use "?" or "#" in resource identifiers, as they terminate the named resource path. For example, "Foo?3" is treated as "Foo".

    Returns

    • string
      string
      string
      string

      The most appropriate string value of the specified resource for the default ResourceContext.

    Remarks

    Example:

    var string = resourceLoader.getString('Header1');
    
  • GetStringForReference(Uri)
    GetStringForReference(Uri)
    GetStringForReference(Uri)
    GetStringForReference(Uri)
    Note

    GetStringForReference may be altered or unavailable for releases after Windows 8.1. Instead, use GetStringForUri(Uri).

    Returns the most appropriate string value of a resource, specified as a Uri for a resource identifier, for the default ResourceContext of the currently running app.

    public static string GetStringForReference(Uri uri)public static string GetStringForReference(Uri uri)Public Static Function GetStringForReference(uri As Uri) As stringpublic static string GetStringForReference(Uri uri)

    Parameters

    Returns

    • string
      string
      string
      string

      The most appropriate string value of the specified resource for the default ResourceContext.

    Remarks

    Uri objects require a scheme to be identified. In this context, the ms-resource scheme must be specified in the Uri passed to the method. See How to load string resources.

  • GetStringForUri(Uri)
    GetStringForUri(Uri)
    GetStringForUri(Uri)
    GetStringForUri(Uri)

    Returns the most appropriate string value of a resource, specified by a Uniform Resource Identifier (URI) resource identifier, for the default ResourceContext of the currently running app.

    public string GetStringForUri(Uri uri)public string GetStringForUri(Uri uri)Public Function GetStringForUri(uri As Uri) As stringpublic string GetStringForUri(Uri uri)

    Parameters

    • uri

      A Uniform Resource Identifier (URI) that represents the resource to be retrieved.

    Returns

    • string
      string
      string
      string

      The most appropriate string value of the specified resource for the default ResourceContext.

    Remarks

    Uniform Resource Identifier (URI) objects require a scheme to be identified. In this context, the ms-resource scheme must be specified in the Uniform Resource Identifier (URI) passed to the method.

    Errors

    This method fails with an exception if the supplied Uniform Resource Identifier (URI) is for some other protocol, if the requested resource is not found, or if the requested resource is not a string.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ActivatableAttribute
Windows.Foundation.Metadata.ActivatableAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.ThreadingAttribute

Details

Assembly

Windows.ApplicationModel.Resources.dll