ResourceMap 類別

定義

相關資源的集合,通常是針對特定應用程式套件,或特定套件的資源檔。

public ref class ResourceMap sealed : IIterable<IKeyValuePair<Platform::String ^, NamedResource ^> ^>, IMapView<Platform::String ^, NamedResource ^>
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class ResourceMap final : IIterable<IKeyValuePair<winrt::hstring, NamedResource const&>>, IMapView<winrt::hstring, NamedResource const&>
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class ResourceMap : IEnumerable<KeyValuePair<string,NamedResource>>, IReadOnlyDictionary<string,NamedResource>
Public NotInheritable Class ResourceMap
Implements IEnumerable(Of KeyValuePair(Of String, NamedResource)), IReadOnlyDictionary(Of String, NamedResource)
繼承
Object Platform::Object IInspectable ResourceMap
屬性
實作

Windows 需求

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

範例

此範例是以 應用程式資源和當地語系化範例的案例 8 為基礎。 請參閱完整解決方案的範例。

private void ShowText()
{
    ResourceContext defaultContextForCurrentView = ResourceContext.GetForCurrentView();
    ResourceMap stringResourcesResourceMap = ResourceManager.Current.MainResourceMap.GetSubtree("Resources");
    Scenario8MessageTextBlock.Text = stringResourcesResourceMap.GetValue("string1", defaultContextForCurrentView).ValueAsString;
}
void Scenario8::ShowText()
{
    ResourceContext^ defaultContextForCurrentView = ResourceContext::GetForCurrentView();
    auto resourceStringMap = ResourceManager::Current->MainResourceMap->GetSubtree("Resources");
    Scenario8MessageTextBlock->Text = resourceStringMap->GetValue("string1", defaultContextForCurrentView)->ValueAsString;
}

備註

資源識別碼語法

此類別的許多方法都會使用資源識別碼作為參數。 資源識別碼會被視為統一資源識別項 (URI) 片段,受限於統一資源識別項 (URI) 語意。 例如,GetValue (「Caption%20」) 會被視為 GetValue (「Caption 」) 。

勿在資源識別碼中使用「?」或「#」,因為它們會終止資源路徑評估。 例如,「MyResource?3」會被視為「MyResource」。

屬性

Size

取得地圖中的資源數目。

Uri

取得可用來參考這個 ResourceMap的 URI。

方法

First()

傳回反覆運算器,以列舉地圖中的專案。

GetSubtree(String)

會傳回 ResourceMap ,代表另一個 ResourceMap的一部分,通常用來存取應用程式套件內的特定資源檔。

這個方法會尋找子樹、上階、同層級和同層級對應至此資源對應,以及最上層地圖。 它會傳回指定資源對應識別碼所代表的資源對應,相對於此資源對應。 這個方法通常用來對特定資源子集進行更簡單的參考,例如單一資源檔或檔案目錄。

GetValue(String)

注意

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

針對預設內容中的資源識別碼所指定的資源,傳回最適合的候選項目。

GetValue(String, ResourceContext)

針對提供之內容的資源識別碼所指定的資源,傳回最適合的候選項目。

HasKey(String)

判斷對應是否可以擷取具有指定資源識別碼的資源。

Lookup(String)

傳回對應中指定資源識別碼上的 NamedResource

Split(IMapView<String,NamedResource>, IMapView<String,NamedResource>)

將地圖檢視分割成兩個檢視。

適用於

另請參閱