磁贴和 toast 通知的语言、比例和高对比度支持Tile and toast notification support for language, scale, and high contrast

你的磁贴和 toast 可以加载为显示语言、显示比例系数、高对比度和其他运行时上下文定制的字符串和图像。Your tiles and toasts can load strings and images tailored for display language, display scale factor, high contrast, and other runtime contexts. 有关如何在资源文件名称中使用限定符的背景,请参阅 为语言、缩放和其他限定符应用图标和徽标定制资源。For background on how to use qualifiers in the names of your resource files, see Tailor your resources for language, scale, and other qualifiers and App icons and logos.

有关对应用进行本地化的价值主张的详细信息,请参阅全球化和本地化For more info about the value proposition of localizing your app, see Globalization and localization.

从模板引用字符串资源Refer to a string resource from a template

在你的磁贴或 toast 模板中,你可以使用后跟简单字符串资源标识符的 ms-resource URI(统一资源标识符)方案来引用字符串资源。In your tile or toast template, you can refer to a string resource using the ms-resource URI (Uniform Resource Identifier) scheme followed by a simple string resource identifier. 例如,如果你有一个包含名称为“Farewell”的资源条目的 Resources.resx 文件,则必须具有一个标识符为“Farewell”的字符串资源。For example, if you have a Resources.resx file that contains a resource entry whose name is "Farewell", then you have a string resource with the identifier "Farewell". 有关字符串资源标识符和资源文件 (.resw) 的详细信息,请参阅本地化 UI 和应用包清单中的字符串For more info on string resource identifiers and Resources Files (.resw), see Localize strings in your UI and app package manifest.

这是“Farewell”字符串资源标识符引用在使用 ms-resource 的模板内容的文本正文中的外观。This is how a reference to the "Farewell" string resource identifier would look in the text body of your template content, using ms-resource.

<text id="1">ms-resource:Farewell</text>

如果你省略 ms-resource URI 方案,则文本正文只是一个字符串参数, 不是 标识符引用。If you omit the ms-resource URI scheme, then the text body is just a string literal, and not a reference to an identifier.

<text id="1">Farewell</text>

引用模板中的图像资源Refer to an image resource from a template

在你的磁贴或 toast 模板中,你可以使用后跟图像资源名称的 ms-appx URI(统一资源标识符)方案来引用图像资源。In your tile or toast template, you can refer to an image resource using the ms-appx URI (Uniform Resource Identifier) scheme followed by the name of the image resource. 方法与你引用 XAML 标记中的图像资源的方法相同(有关详细信息,请参阅引用 XAML 标记和代码中的图像或其他资产)。This is the same way that you refer to an image resource in XAML markup (for more details, see Reference an image or other asset from XAML markup and code).

例如,你可以这样给文件夹命名。For example, you might name folders like this.

\Assets\Images\contrast-standard\welcome.png
\Assets\Images\contrast-high\welcome.png

在本例中,你有一个图像资源且其名称(作为绝对路径)为 /Assets/Images/welcome.pngIn that case, you have a single image resource and its name (as an absolute path) is /Assets/Images/welcome.png. 下面介绍如何在模板中使用该名称。Here’s how you use that name in your template.

<image id="1" src="ms-appx:///Assets/Images/welcome.png"/>

注意在此示例 URI 中,方案(“ms-appx”)后依次跟随“://”和绝对路径(以“/”开头的绝对路径)。Notice how in this example URI the scheme ("ms-appx") is followed by "://" which is followed by an absolute path (an absolute path begins with "/").

在云中托管和加载图像Hosting and loading images in the cloud

ms-resourcems-appx URI 方案执行自动限定符匹配,以查找最适合当前上下文的资源。The ms-resource and ms-appx URI schemes perform automatic qualifier matching to find the resource that's most appropriate for the current context. Web URI 方案(如 httphttpsftp)无法执行任何此类自动匹配。Web URI schemes (for example, http, https, and ftp) do not perform any such automatic matching.

改为在你的图像的 URI 上附加一个描述请求的限定符值的查询字符串。Instead, append onto your image's URI a query string describing the requested qualifier value or values.

<image id="1" src="http://www.contoso.com/Assets/Images/welcome.png?ms-lang=en-US"/>

然后,在提供图像的应用服务中,实施检查和使用查询字符串确定要返回的图像的 HTTP 处理程序。Then, in the app service that provides your images, implement an HTTP handler that inspects and uses the query string to determine which image to return.

你还需在 磁贴toast 通知 XML 负载中将 addImageQuery 属性设置为 trueYou also need to set the addImageQuery attribute to true in the tile or toast notification XML payload. AddImageQuery 属性显示在 visual binding image 磁贴和 toast 架构的、和元素中。The addImageQuery attribute appears in the visual, binding, and image elements of both the tile and toast schemas. 在元素上显式设置 addImageQuery 将覆盖在上级元素上设置的任何值。Explicitly setting addImageQuery on an element overrides any value set on an ancestor. 例如,在 image 元素中为 trueaddImageQuery 值覆盖在其父级 binding 元素中为 falseaddImageQueryFor instance, an addImageQuery value of true in an image element overrides an addImageQuery of false in its parent binding element.

以下是你可以使用的查询字符串。These are the query strings you can use.

限定符Qualifier 查询字符串Query string 示例Example
缩放Scale ms-scalems-scale ?ms-scale=400?ms-scale=400
语言Language ms-langms-lang ?ms-lang=en-US?ms-lang=en-US
与此示例Contrast ms-contrastms-contrast ?ms-contrast=high?ms-contrast=high

有关你在查询字符串中可以使用的所有可能的限定符值的参考表,请参阅 ResourceContext.QualifierValuesFor a reference table of all the possible qualifier values that you can use in your query strings, see ResourceContext.QualifierValues.

重要的 APIImportant APIs