private void ShowToast(ITracer tracer, NamedPipeMessages.Notification.Request request) { ToastData toastData = new ToastData(); toastData.Visual = new VisualData(); BindingData binding = new BindingData(); toastData.Visual.Binding = binding; binding.Template = "ToastGeneric"; binding.Items = new XmlList <BindingItem>(); binding.Items.Add(new BindingItem.TextData(request.Title)); binding.Items.AddRange(request.Message.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).Select(t => new BindingItem.TextData(t))); XmlDocument toastXml = new XmlDocument(); using (StringWriter stringWriter = new StringWriter()) using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings { OmitXmlDeclaration = true })) { XmlSerializer serializer = new XmlSerializer(toastData.GetType()); XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add(string.Empty, string.Empty); serializer.Serialize(xmlWriter, toastData, namespaces); toastXml.LoadXml(stringWriter.ToString()); } ToastNotification toastNotification = new ToastNotification(toastXml); ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(ServiceAppId); toastNotifier.Show(toastNotification); }
public void Notify(string title, string message, string actionButtonTitle, string callbackArgs) { // Reference: https://docs.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/adaptive-interactive-toasts ToastData toastData = new ToastData(); toastData.Visual = new VisualData(); BindingData binding = new BindingData(); toastData.Visual.Binding = binding; // ToastGeneric- Our toast contains VFSForGit icon and text binding.Template = "ToastGeneric"; binding.Items = new XmlList <BindingItem>(); binding.Items.Add(new BindingItem.TextData(title)); binding.Items.Add(new BindingItem.TextData(message)); string logo = "file:///" + Path.Combine(ProcessHelper.GetCurrentProcessLocation(), ScalarIconName); binding.Items.Add(new BindingItem.ImageData() { Source = logo, Placement = "appLogoOverride", HintCrop = "circle" }); if (!string.IsNullOrEmpty(actionButtonTitle)) { ActionsData actionsData = new ActionsData(); actionsData.Actions = new XmlList <ActionItem>(); actionsData.Actions.Add(new ActionItem() { Content = actionButtonTitle, Arguments = string.IsNullOrEmpty(callbackArgs) ? string.Empty : callbackArgs, ActivationType = "background" }); toastData.Actions = actionsData; } XmlDocument toastXml = new XmlDocument(); using (StringWriter stringWriter = new StringWriter()) using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, new XmlWriterSettings { OmitXmlDeclaration = true })) { XmlSerializer serializer = new XmlSerializer(toastData.GetType()); XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add(string.Empty, string.Empty); serializer.Serialize(xmlWriter, toastData, namespaces); toastXml.LoadXml(stringWriter.ToString()); } ToastNotification toastNotification = new ToastNotification(toastXml); toastNotification.Activated += this.ToastActivated; toastNotification.Dismissed += this.ToastDismissed; toastNotification.Failed += this.ToastFailed; ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier(ServiceAppId); toastNotifier.Show(toastNotification); }