ResourceLoader 類別

定義

提供應用程式資源的簡化存取,例如應用程式 UI 字串。

適用于 UWP 的對等 WinUI 2 APIMicrosoft.Windows.ApplicationModel.Resources.ResourceLoader (Windows 應用程式 SDK,請參閱Windows 應用程式 SDK命名空間) 。

public ref class ResourceLoader sealed
/// [Windows.Foundation.Metadata.Activatable(Windows.ApplicationModel.Resources.IResourceLoaderFactory, 65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class ResourceLoader final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(Windows.ApplicationModel.Resources.IResourceLoaderFactory, 65536, "Windows.Foundation.UniversalApiContract")]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
class ResourceLoader final
[Windows.Foundation.Metadata.Activatable(typeof(Windows.ApplicationModel.Resources.IResourceLoaderFactory), 65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class ResourceLoader
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(typeof(Windows.ApplicationModel.Resources.IResourceLoaderFactory), 65536, "Windows.Foundation.UniversalApiContract")]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class ResourceLoader
function ResourceLoader(name)
Public NotInheritable Class ResourceLoader
繼承
Object Platform::Object IInspectable ResourceLoader
屬性

Windows 需求

裝置系列
Windows 10 (已於 10.0.10240.0 引進)
API contract
Windows.Foundation.UniversalApiContract (已於 v1.0 引進)

範例

使用 ResourceLoader.GetString 方法來取得 「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");

備註

ResourceLoader物件會封裝特定的ResourceMapResourceCoNtext,並結合在簡單的 API 中。

取得 ResourceLoader 時,可以指定特定的資源對應;如果未指定任何資源對應, ResourceLoader 將會提供應用程式主要資源對應之「資源」子樹的存取權。

一般而言,資源可能會敏感于縮放或其他顯示特性。 因此,資源內容通常會與特定檢視相關聯。 由於 ResourceLoader 會封裝資源內容,因此這也適用于 ResourceLoader。 使用GetForCurrentView取得的ResourceLoader具有與其取得之檢視相關聯的資源內容。 您也可以使用GetForViewIndependentUse取得與檢視無關的 ResourceLoader

  • 使用 DisplayInformation 類別而非已被取代的 DisplayProperties 類別,取得目前檢視的縮放比例。
  • 設定明確寬度和高度元素的應用程式仍應該正常運作,但可能顯示模糊影像以外的應用程式。
  • 透過GetForViewIndependentUse取得ResourceLoader,以取得未與任何檢視相關聯的資源。

另請參閱 螢幕大小和中斷點

版本歷程記錄

Windows 版本 SDK 版本 已新增值
1903 18362 GetForUICoNtext

建構函式

ResourceLoader()

注意

ResourceLoader () 可能會在Windows 8.1之後變更或無法使用版本。 請改用 GetForCurrentView ()

建構目前執行中應用程式主要ResourceMap之 「Resources」 子樹的新ResourceLoader物件。

適用于 UWP 的對等 WinUI 2 API:Windows 應用程式 SDK中 WinUI的 ResourceLoader () (,請參閱Windows 應用程式 SDK命名空間) 。

ResourceLoader(String)

注意

ResourceLoader (String) 可能會在Windows 8.1之後變更或無法使用。 請改用 GetForCurrentView (String)

為指定的ResourceMap建構新的ResourceLoader物件。

適用于 UWP 的對等 WinUI 2 APIResourceLoader (String) (for WinUI Windows 應用程式 SDK,請參閱Windows 應用程式 SDK命名空間) 。

方法

GetDefaultPriPath(String)

提供應用程式檔案的位置 resources.pri

GetForCurrentView()

取得目前執行中應用程式主要ResourceMapResources 子樹ResourceLoader物件。 此 ResourceLoader 會使用與目前檢視相關聯的預設內容。

GetForCurrentView(String)

取得指定ResourceMap 的 ResourceLoader物件。 此 ResourceLoader 會使用與目前檢視相關聯的預設內容。

GetForUIContext(UIContext)

取得指定之 UICoNtextResourceLoader物件。

GetForViewIndependentUse()

取得目前執行中應用程式主要ResourceMapResources 子樹ResourceLoader物件。 此 ResourceLoader 會使用未與任何檢視相關聯的預設內容。

GetForViewIndependentUse(String)

取得指定ResourceMap 的 ResourceLoader物件。 此 ResourceLoader 會使用未與任何檢視相關聯的預設內容。

GetString(String)

針對使用ResourceLoader.GetForCurrentView 取得 ResourceLoader之檢視的預設ResourceCoNtext,傳回資源識別碼所指定的資源最適當的字串值。

適用于 UWP 的對等 WinUI 2 APIMicrosoft.Windows.ApplicationModel.Resources.ResourceLoader.GetString (for WinUI 在Windows 應用程式 SDK中,請參閱Windows 應用程式 SDK命名空間) 。

GetStringForReference(Uri)

注意

GetStringForReference 可能會在Windows 8.1之後變更或無法使用版本。 請改用 GetStringForUri

針對目前執行中應用程式的預設ResourceCoNtext,傳回資源最適當的字串值,指定為資源識別碼的URI

GetStringForUri(Uri)

針對目前執行中應用程式的預設 ResourceCoNtext ,傳回資源 (URI) 資源識別碼所指定的資源最適當的字串值。

適用于 UWP 的對等 WinUI 2 APIMicrosoft.Windows.ApplicationModel.Resources.ResourceLoader.GetStringForUri (Windows 應用程式 SDK,請參閱) Windows 應用程式 SDK命名空間

適用於

另請參閱