對語言、縮放比例及高對比的磚和快顯通知支援Tile and toast notification support for language, scale, and high contrast

您的磚和快顯通知可以載入針對顯示語言、 顯示比例因數、高對比和其他執行時間內容量身打造的字串和影像。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

在您的磚或快顯通知範本中,可以使用後面加上簡單字串資源識別碼的 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. 例如,如果您的 Resources.resx 檔案包含名稱為「Farewell」的資源項目,則您會有包含識別碼「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

在您的磚或快顯通知範本中,可以使用後面加上影像資源名稱的 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.

您也必須在 快顯通知 XML 承載中,將 addImageQuery 屬性設定為 trueYou also need to set the addImageQuery attribute to true in the tile or toast notification XML payload. AddImageQuery 屬性會出現在圖格和快顯快顯 visual 架構的、 binding 和元素中 imageThe 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 元素的 addImageQuerytrue 會覆寫其上層 binding 元素的 addImageQueryfalseFor 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.

QualifierQualifier 查詢字串Query string 範例Example
調整Scale ms-scalems-scale ?ms-scale=400?ms-scale=400
LanguageLanguage 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