共用方式為


ResourceQualifierVectorView 類別

定義

ResourceQualifier物件的向量中無法變更的檢視。

public ref class ResourceQualifierVectorView sealed : IIterable<ResourceQualifier ^>, IVectorView<ResourceQualifier ^>
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class ResourceQualifierVectorView final : IIterable<ResourceQualifier>, IVectorView<ResourceQualifier>
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class ResourceQualifierVectorView : IEnumerable<ResourceQualifier>, IReadOnlyList<ResourceQualifier>
Public NotInheritable Class ResourceQualifierVectorView
Implements IEnumerable(Of ResourceQualifier), IReadOnlyList(Of ResourceQualifier)
繼承
Object Platform::Object IInspectable ResourceQualifierVectorView
屬性
實作

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', 'qualifier 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 += "        Qualifier: " + qualifierName + ": " + qualifierValue + "\r\n";
            outText += "        Matching: IsMatch (" + qualifier.IsMatch.ToString() + ")  " + "IsDefault (" + qualifier.IsDefault.ToString() + ")" + "\r\n";
            j++;
        }
        i++;
    }

    this.Scenario10TextBlock.Text += outText + "\r\n";
}
void SDKTemplate::Scenario10::Scenario10Button_Show_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    Button^ b = safe_cast<Button^>(sender);
    if (b != nullptr)
    {
        // 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)
        auto context = ResourceContext::GetForCurrentView()->Clone();

        auto selectedLanguage = Scenario10ComboBox_Language->SelectedValue;
        auto selectedScale = Scenario10ComboBox_Scale->SelectedValue;
        auto selectedContrast = Scenario10ComboBox_Contrast->SelectedValue;
        auto selectedHomeRegion = Scenario10ComboBox_HomeRegion->SelectedValue;

        if (selectedLanguage != nullptr)
        {
            context->QualifierValues->Insert("language", selectedLanguage->ToString());
        }
        if (selectedScale != nullptr)
        {
            context->QualifierValues->Insert("scale", selectedScale->ToString());
        }
        if (selectedContrast != nullptr)
        {
            context->QualifierValues->Insert("contrast", selectedContrast->ToString());
        }
        if (selectedHomeRegion != nullptr)
        {
            context->QualifierValues->Insert("homeregion", selectedHomeRegion->ToString());
        }

        Platform::Collections::Vector<String^>^ resourceIds = ref new Platform::Collections::Vector<String^>();
        //auto resourceIds = new list<String^>();
        resourceIds->Append("LanguageOnly");
        resourceIds->Append("ScaleOnly");
        resourceIds->Append("ContrastOnly");
        resourceIds->Append("HomeRegionOnly");
        resourceIds->Append("MultiDimensional");
        Scenario10_SearchMultipleResourceIds(context, resourceIds);
    }
}

void SDKTemplate::Scenario10::Scenario10_SearchMultipleResourceIds(ResourceContext^ context, Platform::Collections::Vector<String^>^ resourceIds)
{
    Scenario10TextBlock->Text = "";
    auto dimensionMap = ResourceManager::Current->MainResourceMap->GetSubtree("dimensions");

    for (unsigned int it = 0; it < resourceIds->Size; it++)
    {
        String^ id = resourceIds->GetAt(it);
        NamedResource^ namedResource = dimensionMap->Lookup(id);
        if (namedResource)
        {
            auto resourceCandidates = namedResource->ResolveAll(context);
            Scenario10_ShowCandidates(resourceIds->GetAt(it), resourceCandidates);
        }
    }
}

void SDKTemplate::Scenario10::Scenario10_ShowCandidates(String^ resourceId, Windows::Foundation::Collections::IVectorView<ResourceCandidate^>^ resourceCandidates)
{
    // print 'resourceId', 'found value', 'qualifier info', 'matching condition'
    String^ outText = "resourceId: dimensions\\" + resourceId + "\r\n";

    for(unsigned int i =0; i < resourceCandidates->Size; i++)
    {
        ResourceCandidate^ candidate = resourceCandidates->GetAt(i);
        auto value = candidate->ValueAsString;

        outText += "    Candidate " + i.ToString() + ":" + value + "\r\n";
        for (unsigned int j = 0; j < candidate->Qualifiers->Size; j++)
        {
            auto qualifier = candidate->Qualifiers->GetAt(j);
            auto qualifierName = qualifier->QualifierName;
            auto qualifierValue = qualifier->QualifierValue;
            outText += "        Qualifier: " + qualifierName + ": " + qualifierValue + "\r\n";
            outText += "        Matching: IsMatch (" + qualifier->IsMatch.ToString() + ")  " + "IsDefault (" + qualifier->IsDefault.ToString() + ")" + "\r\n";
        }
    }
    this->Scenario10TextBlock->Text += outText + "\r\n";
}

備註

列舉 C# 或 Microsoft Visual Basic 中的集合

ResourceQualifierVectorView 是可列舉的,因此您可以使用 C# 中的 foreach 之類的語言特定語法來列舉集合中的專案。 編譯器會為您執行類型轉換,而且您不需要明確地轉換 。 IEnumerable<ResourceQualifier> 如果您需要明確轉換,例如,如果您想要呼叫GetEnumerator,請使用ResourceQualifier條件約束轉換成IEnumerable < T >

屬性

Size

取得檢視中的 ResourceQualifier 物件數目。

方法

First()

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

GetAt(UInt32)

傳回檢視中指定索引處的 ResourceQualifier

GetMany(UInt32, ResourceQualifier[])

會傳回從檢視中指定索引開始的 ResourceQualifier 物件。

IndexOf(ResourceQualifier, UInt32)

傳回檢視中指定 之 ResourceQualifier 的索引。

適用於

另請參閱