語言

ResourceLoader 類別

定義

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

public ref class ResourceLoader sealed
/// [Windows.Foundation.Metadata.Activatable(65536, "Microsoft.Windows.ApplicationModel.Resources.MrtContract")]
/// [Windows.Foundation.Metadata.Activatable(Microsoft.Windows.ApplicationModel.Resources.IResourceLoaderFactory, 65536, "Microsoft.Windows.ApplicationModel.Resources.MrtContract")]
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.Windows.ApplicationModel.Resources.MrtContract, 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.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Microsoft.Windows.ApplicationModel.Resources.MrtCoreContract")]
/// [Windows.Foundation.Metadata.Activatable(Microsoft.Windows.ApplicationModel.Resources.IResourceLoaderFactory, 65536, "Microsoft.Windows.ApplicationModel.Resources.MrtCoreContract")]
/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.Windows.ApplicationModel.Resources.MrtCoreContract, 65536)]
class ResourceLoader final
[Windows.Foundation.Metadata.Activatable(65536, "Microsoft.Windows.ApplicationModel.Resources.MrtContract")]
[Windows.Foundation.Metadata.Activatable(typeof(Microsoft.Windows.ApplicationModel.Resources.IResourceLoaderFactory), 65536, "Microsoft.Windows.ApplicationModel.Resources.MrtContract")]
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.Windows.ApplicationModel.Resources.MrtContract), 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.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(65536, "Microsoft.Windows.ApplicationModel.Resources.MrtCoreContract")]
[Windows.Foundation.Metadata.Activatable(typeof(Microsoft.Windows.ApplicationModel.Resources.IResourceLoaderFactory), 65536, "Microsoft.Windows.ApplicationModel.Resources.MrtCoreContract")]
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.Windows.ApplicationModel.Resources.MrtCoreContract), 65536)]
public sealed class ResourceLoader
function ResourceLoader(fileName, resourceMap)
Public NotInheritable Class ResourceLoader
繼承
Object Platform::Object IInspectable ResourceLoader
屬性

備註

ResourceLoader 物件封裝了特定的 ResourceMap 與 ResourceContext,並結合於一個簡單的 API。

當取得 ResourceLoader 時,可以指定特定的資源映射;若未指定資源映射, ResourceLoader 將提供對應用程式主資源映射「Resources」子樹的存取權限。

一般而言,資源可能對縮放或其他顯示特性敏感。 因此,資源上下文通常會與特定的視圖相關聯。 由於 ResourceLoader 封裝了資源上下文,這同樣適用於 ResourceLoader。

  • 可透過使用 DisplayInformation 類別取代已棄用的 DisplayProperties 類別,取得目前視圖的縮放因子。
  • 設定元素寬度和高度的應用程式應該還是能正常運作,除了可能會顯示模糊的圖片。

另請參閱 螢幕尺寸與中斷點。

建構函式

名稱 Description
ResourceLoader()

為目前執行的應用程式主 ResourceMap 的「Resources」子樹建構一個新的 ResourceLoader 物件。

ResourceLoader(String, String)

為給定的上下文和地圖建立一個 ResourceLoader 。

ResourceLoader(String)

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

方法

名稱 Description
GetDefaultResourceFilePath()

取得預設的資源檔案路徑,若未指定自訂路徑,則是 ResourceLoader 建立的路徑。

GetString(String)

回傳資源最合適的字串值,由資源識別碼指定。

GetStringForUri(Uri)

回傳資源最合適的字串值,該值由統一資源識別碼(URI)資源識別碼指定,適用於目前執行應用程式的預設 ResourceContext 。

適用於