Export (0) Print
Expand All
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

ResourceLoader class

Applies to Windows and Windows Phone

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

Syntax


var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.getForCurrentView();
var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.getForCurrentView(string);

Attributes

[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]

Members

The ResourceLoader class has these types of members:

Constructors

The ResourceLoader class has these constructors.

ConstructorDescription
ResourceLoader Constructs a new ResourceLoader object for the Resources subtree of the currently running app's main ResourceMap.
ResourceLoader(String) Constructs a new ResourceLoader object for the specified ResourceMap.

 

Methods

The ResourceLoader class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
GetForCurrentView Gets a ResourceLoader object for the Resources subtree of the currently running app's main ResourceMap.
GetForCurrentView(String) Gets a ResourceLoader object for the specified ResourceMap.
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) Gets a ResourceLoader object for the specified ResourceMap. This ResourceLoader uses a default context that's not associated with any view.
GetString 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 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 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.

 

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 Windows 8: Windows Store 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 Windows 8.1: Multiple monitors can display multiple Windows Store 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 Guidelines for scaling to pixel density.

Examples

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


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


Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

End of client support

Windows 8.1

End of server support

Windows Server 2012 R2

Namespace

Windows.ApplicationModel.Resources
Windows::ApplicationModel::Resources [C++]

Metadata

Windows.winmd

See also

GetForCurrentView
GetForCurrentView(String)
GetForViewIndependentUse
GetForViewIndependentUse(String)
ResourceMap
ResourceContext
Creating and retrieving resources in Windows Store apps
Guidelines for window sizes and scaling to screens
Guidelines for scaling to pixel density
Application resources and localization sample

 

 

Show:
© 2014 Microsoft