共用方式為


ResourceCandidate 類別

定義

代表指定 NamedResource的單一可能值、與該資源相關聯的限定詞,以及這些限定詞符合解析內容的方式。

public ref class ResourceCandidate sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class ResourceCandidate final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class ResourceCandidate
Public NotInheritable Class ResourceCandidate
繼承
Object Platform::Object IInspectable ResourceCandidate
屬性

Windows 需求

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

範例

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

private void Scenario10Button_Show_Click(object sender, RoutedEventArgs e)
{
    Button b = sender as Button;
    if (b != null)
    {
        // Use a cloned context for this scenario so that qualifier values set
        // in this scenario don't impact behavior in other scenarios that
        // use a default context for the view (crossover effects between
        // the scenarios will not be expected).
        var context = ResourceContext.GetForCurrentView().Clone();

        var selectedLanguage = Scenario10ComboBox_Language.SelectedValue;
        var selectedScale = Scenario10ComboBox_Scale.SelectedValue;
        var selectedContrast = Scenario10ComboBox_Contrast.SelectedValue;
        var selectedHomeRegion = Scenario10ComboBox_HomeRegion.SelectedValue;

        if (selectedLanguage != null)
        {
            context.QualifierValues["language"] = selectedLanguage.ToString();
        }
        if (selectedScale != null)
        {
            context.QualifierValues["scale"] = selectedScale.ToString();
        }
        if (selectedContrast != null)
        {
            context.QualifierValues["contrast"] = selectedContrast.ToString();
        }
        if (selectedHomeRegion != null)
        {
            context.QualifierValues["homeregion"] = selectedHomeRegion.ToString();
        }
        Scenario10_SearchMultipleResourceIds(context, new string[] { "LanguageOnly", "ScaleOnly", "ContrastOnly", "HomeRegionOnly", "MultiDimensional" });
    }
}

void Scenario10_SearchMultipleResourceIds(ResourceContext context, string[] resourceIds)
{
    this.Scenario10TextBlock.Text = "";
    var dimensionMap = ResourceManager.Current.MainResourceMap.GetSubtree("dimensions");

    foreach (var id in resourceIds)
    {
        NamedResource namedResource;
        if (dimensionMap.TryGetValue(id, out namedResource))
        {
            var resourceCandidates = namedResource.ResolveAll(context);
            Scenario10_ShowCandidates(id, resourceCandidates);
        }
    }
}

void Scenario10_ShowCandidates(string resourceId, IReadOnlyList<ResourceCandidate> resourceCandidates)
{
    // Print 'resourceId', 'found value', 'qualifer info', 'matching condition'
    string outText = "resourceId: dimensions\\" + resourceId + "\r\n";
    int i = 0;
    foreach (var candidate in resourceCandidates)
    {
        var value = candidate.ValueAsString;
        outText += "    Candidate " + i.ToString() + ":" + value + "\r\n";
        int j = 0;
        foreach (var qualifier in candidate.Qualifiers)
        {
            var qualifierName = qualifier.QualifierName;
            var qualifierValue = qualifier.QualifierValue;
            outText += "        Qualifer: " + qualifierName + ": " + qualifierValue + "\r\n";
            outText += "        Matching: IsMatch (" + qualifier.IsMatch.ToString() + ")  " + "IsDefault (" + qualifier.IsDefault.ToString() + ")" + "\r\n";
            j++;
        }
        i++;
    }

    this.Scenario10TextBlock.Text += outText + "\r\n";
}

備註

版本歷程記錄

Windows 版本 SDK 版本 已新增值
1903 18362 種類

屬性

IsDefault

指出此 ResourceCandidate 是否可以作為任何內容的預設後援值。

IsMatch

指出此 ResourceCandidate 是否符合其評估的 ResourceCoNtext

IsMatchAsDefault

指出此 ResourceCandidate 是否比對 ResourceCoNtext ,因為其評估結果為 true 比對、預設後援值,或與預設後援 (的混合比對,也就是與某些限定詞相關的比對,但針對其他限定詞使用預設後援值) 。

Kind

取得封裝在此 ResourceCandidate中的資源類型。

Qualifiers

取得與此 ResourceCandidate相關聯的限定詞。

ValueAsString

取得這個 ResourceCandidate的值,以字串表示。

方法

GetQualifierValue(String)

傳回限定詞的值,指定其名稱。

GetValueAsFileAsync()

以非同步方式傳回 StorageFile ,以存取此 ResourceCandidate的值。 這僅適用于屬於檔案的特定 ResourceCandidate類型。

GetValueAsStreamAsync()

以非同步方式傳回 IRandomAccessStream ,以存取此 ResourceCandidate的值。

適用於

另請參閱