// ****************************************************************** // Copyright (c) Microsoft. All rights reserved. // This code is licensed under the MIT License (MIT). // THE CODE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, // INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH // THE CODE OR THE USE OR OTHER DEALINGS IN THE CODE. // ****************************************************************** using System; using System.Collections.Generic; using Microsoft.Toolkit.Uwp.Notifications.Adaptive; namespace Microsoft.Toolkit.Uwp.Notifications { /// /// Generic Toast binding, where you provide text, images, and other visual elements for your Toast notification. /// public sealed class ToastBindingGeneric { /// /// The contents of the body of the Toast, which can include , , and (added in Anniversary Update). Also, elements must come before any other elements. If an element is placed after any other element, an exception will be thrown when you try to retrieve the Toast XML content. And finally, certain properties like HintStyle aren't supported on the root children text elements, and only work inside an . If you use on devices without the Anniversary Update, the group content will simply be dropped. /// public IList Children { get; private set; } = new List(); /// /// An optional override of the logo displayed on the Toast notification. /// public ToastGenericAppLogo AppLogoOverride { get; set; } /// /// New in Anniversary Update: An optional hero image (a visually impactful image displayed on the Toast notification). On devices without the Anniversary Update, the hero image will simply be ignored. /// public ToastGenericHeroImage HeroImage { get; set; } /// /// New in Anniversary Update: An optional text element that is displayed as attribution text. On devices without the Anniversary Update, this text will appear as if it's another element at the end of your Children list. /// public ToastGenericAttributionText Attribution { get; set; } /// /// The target locale of the XML payload, specified as BCP-47 language tags such as "en-US" or "fr-FR". This locale is overridden by any locale specified in binding or text. If this value is a literal string, this attribute defaults to the user's UI language. If this value is a string reference, this attribute defaults to the locale chosen by Windows Runtime in resolving the string. /// public string Language { get; set; } /// /// A default base URI that is combined with relative URIs in image source attributes. /// public Uri BaseUri { get; set; } /// /// Set to "true" to allow Windows to append a query string to the image URI supplied in the Toast notification. Use this attribute if your server hosts images and can handle query strings, either by retrieving an image variant based on the query strings or by ignoring the query string and returning the image as specified without the query string. This query string specifies scale, contrast setting, and language. /// public bool? AddImageQuery { get; set; } internal Element_ToastBinding ConvertToElement() { Element_ToastBinding binding = new Element_ToastBinding(ToastTemplateType.ToastGeneric) { BaseUri = BaseUri, AddImageQuery = AddImageQuery, Language = Language }; // Add children foreach (var child in Children) { var el = (IElement_ToastBindingChild)AdaptiveHelper.ConvertToElement(child); binding.Children.Add(el); } // Add attribution if (Attribution != null) { binding.Children.Add(Attribution.ConvertToElement()); } // If there's hero, add it if (HeroImage != null) { binding.Children.Add(HeroImage.ConvertToElement()); } // If there's app logo, add it if (AppLogoOverride != null) { binding.Children.Add(AppLogoOverride.ConvertToElement()); } return binding; } } }