Skip to content

Latest commit

 

History

History
56 lines (39 loc) · 3.85 KB

resourceloader.md

File metadata and controls

56 lines (39 loc) · 3.85 KB
-api-id -api-type
T:Windows.ApplicationModel.Resources.ResourceLoader
winrt class

Windows.ApplicationModel.Resources.ResourceLoader

-description

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

Equivalent WinUI 2 API for UWP: Microsoft.Windows.ApplicationModel.Resources.ResourceLoader (for WinUI in the Windows App SDK, see the Windows App SDK namespaces).

-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

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

Also see Screen sizes and breakpoints.

Version history

Windows version SDK version Value added
1903 18362 GetForUIContext

-examples

Use the ResourceLoader.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");

-see-also

GetForCurrentView, GetForCurrentView(String), GetForViewIndependentUse, GetForViewIndependentUse(String), ResourceMap, ResourceContext, App resources and the Resource Management System, Application resources and localization sample