ResourceQualifier 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
定義與 ResourceCandidate相關聯的限定詞。
public ref class ResourceQualifier sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class ResourceQualifier final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class ResourceQualifier
Public NotInheritable Class ResourceQualifier
- 繼承
- 屬性
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";
}
屬性
IsDefault |
指出找不到相符專案時,是否應該將此限定詞視為預設相符專案。 |
IsMatch |
指出當具名資源解析為某些指定內容的候選項目時,給定候選項目的指定限定詞是否符合內容。 |
QualifierName |
限定詞的名稱。 |
QualifierValue |
限定詞的值。 |
Score |
指出限定詞比對解析內容程度的分數。 |