ResourceLoader ResourceLoader ResourceLoader ResourceLoader Class

Definition

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

public : sealed class ResourceLoader : IResourceLoader, IResourceLoader2
public sealed class ResourceLoader : IResourceLoader, IResourceLoader2
Public NotInheritable Class ResourceLoader Implements IResourceLoader, IResourceLoader2
var resourceLoader = new resourceLoader();
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

Use the ResourceLoader.GetString | getString method to get the string resource identified by "Farewell".

C#

var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
var text = resourceLoader.GetString("Farewell");

C++

auto resourceLoader = Windows::ApplicationModel::Resources::ResourceLoader::GetForCurrentView();
String^ text = resourceLoader->GetString("Farewell");

JavaScript

var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.getForCurrentView();
var text = resourceLoader.getString('Farewell');

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.

  • In : UWP apps 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 UWP apps 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.

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

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 ResourceLoader()
Public Sub New()
var resourceLoader = new 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.

See Also

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(Platform::String name)
public ResourceLoader(String name)
Public Sub New(name As String)
var resourceLoader = new resourceLoader(name);
Parameters
name
Platform::String String String 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.

See Also

Methods

GetForCurrentView() GetForCurrentView() GetForCurrentView() GetForCurrentView()

Gets a ResourceLoader object for the Resources subtree 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 ResourceLoader
var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.getForCurrentView();
Returns

A resource loader for the Resources subtree of the currently running app's main ResourceMap.

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 UWP apps 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.

See Also

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(Platform::String name)
public static ResourceLoader GetForCurrentView(String name)
Public Static Function GetForCurrentView(name As String) As ResourceLoader
var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.getForCurrentView(name);
Parameters
name
Platform::String String String 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 UWP apps 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.

See Also

GetForViewIndependentUse() GetForViewIndependentUse() GetForViewIndependentUse() GetForViewIndependentUse()

Gets a ResourceLoader object for the Resources subtree 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 ResourceLoader
var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.getForViewIndependentUse();
Returns

A resource loader for the Resources subtree of the currently running app's main ResourceMap. This ResourceLoader uses a default context that's not associated with any view. You can't use this ResourceLoader to retrieve any resource that has resource candidates qualified for scale.

See Also

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(Platform::String name)
public static ResourceLoader GetForViewIndependentUse(String name)
Public Static Function GetForViewIndependentUse(name As String) As ResourceLoader
var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.getForViewIndependentUse(name);
Parameters
name
Platform::String String String 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

A resource loader for the Resources subtree of the currently running app's main ResourceMap. This ResourceLoader uses a default context that's not associated with any view. You can't use this ResourceLoader to retrieve any resource that has resource candidates qualified for scale.

See Also

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 ResourceLoader.GetForCurrentView.

public : Platform::String GetString(Platform::String resource)
public string GetString(String resource)
Public Function GetString(resource As String) As string
var string = resourceLoader.getString(resource);
Parameters
resource
Platform::String String String 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
Platform::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.

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 Platform::String GetStringForReference(Uri uri)
public static string GetStringForReference(Uri uri)
Public Static Function GetStringForReference(uri As Uri) As string
var string = Windows.ApplicationModel.Resources.ResourceLoader.getStringForReference(uri);
Parameters
uri
Uri Uri Uri Uri

A Uri that represents the resource to be retrieved.

Returns
Platform::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.

See Also

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 : Platform::String GetStringForUri(Uri uri)
public string GetStringForUri(Uri uri)
Public Function GetStringForUri(uri As Uri) As string
var string = resourceLoader.getStringForUri(uri);
Parameters
uri
Uri Uri Uri Uri

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

Returns
Platform::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.

See Also