NamedResource 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示单个逻辑命名资源,例如名为“Header1”的字符串资源。
public ref class NamedResource sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class NamedResource final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class NamedResource
Public NotInheritable Class NamedResource
- 继承
- 属性
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";
}
属性
Candidates |
获取此命名资源的所有可能的候选值。 |
Uri |
获取可用于引用此命名资源的 URI。 |
方法
Resolve() |
根据默认上下文解析此 NamedResource 对象,并返回最合适的候选项。 注意 解析可能在Windows 8.1后更改或不可用于发布。 请改用 Resolve (ResourceContext) 。 |
Resolve(ResourceContext) |
根据提供的上下文解析此 NamedResource 对象,并返回最合适的候选项。 |
ResolveAll() |
根据默认上下文解析此 NamedResource 对象,并按优先顺序返回所有可能的候选项的列表。 注意 在Windows 8.1后,ResolveAll 可能会更改或不可用于发布。 请改用 ResolveAll (ResourceContext) 。 |
ResolveAll(ResourceContext) |
根据提供的上下文解析此 NamedResource 对象,并按优先顺序返回所有可能的候选项的列表。 |