ResourceManager 클래스

정의

애플리케이션 리소스 맵 및 고급 리소스 기능에 대한 액세스를 제공합니다.

public ref class ResourceManager sealed
/// [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 ResourceManager final
[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 ResourceManager
Public NotInheritable Class ResourceManager
상속
Object Platform::Object IInspectable ResourceManager
특성

Windows 요구 사항

디바이스 패밀리
Windows 10 (10.0.10240.0에서 도입되었습니다.)
API contract
Windows.Foundation.UniversalApiContract (v1.0에서 도입되었습니다.)

예제

이 예제는 애플리케이션 리소스 및 지역화 샘플의 시나리오 10을 기반으로 합니다. 보다 완전한 솔루션은 샘플을 참조하세요.

private void SearchMultipleResourceIds(string language, string scale, string contrast, string homeRegion)
{
    // 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)
    ResourceContext context = ResourceContext.GetForCurrentView().Clone();
    context.QualifierValues["language"] = language;
    context.QualifierValues["scale"] = scale;
    context.QualifierValues["contrast"] = contrast;
    context.QualifierValues["homeregion"] = homeRegion;
    var resourceIds = new string[] { "LanguageOnly", "ScaleOnly", "ContrastOnly", "HomeRegionOnly", "MultiDimensional" }
    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);
            string candidateInfo = ShowCandidates(id, resourceCandidates);
        }
    }
    Console.WriteLine(candidateInfo);
}

private string 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";

        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";
        }
        i++;
    }

    return 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^>();
        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";

}

속성

AllResourceMaps

패키지 이름으로 인덱싱된 앱 패키지와 일반적으로 연결된 ResourceMap 개체의 맵을 가져옵니다.

Current

현재 실행 중인 애플리케이션에 대한 ResourceManager 를 가져옵니다.

DefaultContext

현재 실행 중인 애플리케이션의 기본 ResourceContext 를 가져옵니다. 명시적으로 재정의되지 않는 한 기본 ResourceContext 는 지정된 명명된 리소스의 가장 적절한 표현을 결정하는 데 사용됩니다.

참고

DefaultContext는 Windows 8.1 후 릴리스에서 변경되거나 사용할 수 없습니다. 대신 ResourceContext.GetForCurrentView를 사용합니다.

MainResourceMap

현재 실행 중인 애플리케이션의 기본 패키지와 연결된 ResourceMap을 가져옵니다.

메서드

GetAllNamedResourcesForPackage(String, ResourceLayoutInfo)

앱 패키지의 명명된 모든 리소스 목록을 가져옵니다.

GetAllSubtreesForPackage(String, ResourceLayoutInfo)

앱 패키지에 대한 리소스 하위 트리의 모든 컬렉션 목록을 가져옵니다.

IsResourceReference(String)

제공된 문자열이 리소스 참조 형식(ms-resource 문자열 URI 식별자)과 일치하는지 여부를 결정합니다.

LoadPriFiles(IIterable<IStorageFile>)

하나 이상의 PRI(패키지 리소스 인덱스) 파일을 로드하고 해당 내용을 기본 리소스 관리자에 추가합니다.

UnloadPriFiles(IIterable<IStorageFile>)

하나 이상의 PRI(패키지 리소스 인덱스) 파일을 언로드합니다.

적용 대상

추가 정보