ResourceLoader ResourceLoader ResourceLoader ResourceLoader ResourceLoader Class

Definition

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

public : sealed class ResourceLoader : IResourceLoader, IResourceLoader2
struct winrt::Windows::ApplicationModel::Resources::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".

var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForCurrentView();
var text = resourceLoader.GetString("Farewell");
auto resourceLoader{ Windows::ApplicationModel::Resources::ResourceLoader::GetForCurrentView() };
winrt::hstring text{ resourceLoader.GetString(L"Farewell") };
auto resourceLoader = Windows::ApplicationModel::Resources::ResourceLoader::GetForCurrentView();
String^ text = resourceLoader->GetString("Farewell");
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() 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.

ResourceLoader(String) 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.

Methods

GetForCurrentView() 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.

GetForCurrentView(String) 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.

GetForViewIndependentUse() 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.

GetForViewIndependentUse(String) 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.

GetString(String) 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.

GetStringForReference(Uri) 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.

GetStringForUri(Uri) 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.

See Also