Creation of a notification service

This commit is contained in:
Geoffroy BONNEVILLE
2020-04-22 18:12:28 +02:00
parent 61f5e9df0b
commit a9ed588c9a
18 changed files with 201 additions and 194 deletions

View File

@@ -0,0 +1,23 @@
using System;
using Windows.UI.Notifications;
using ModernKeePass.Application.Common.Interfaces;
namespace ModernKeePass.Infrastructure.UWP
{
public class ToastNotificationService: INotificationService
{
public void Show(string title, string text)
{
var notificationXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
var toastElements = notificationXml.GetElementsByTagName("text");
toastElements[0].AppendChild(notificationXml.CreateTextNode(title));
toastElements[1].AppendChild(notificationXml.CreateTextNode(text));
var toast = new ToastNotification(notificationXml)
{
ExpirationTime = DateTime.Now.AddSeconds(5)
};
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
}
}