Update completed solution for chapter 8

This commit is contained in:
Alvin Ashcraft
2023-07-29 14:58:47 -04:00
parent 21e22a0369
commit 4c9e111e61
10 changed files with 387 additions and 7 deletions
@@ -0,0 +1,42 @@
using Microsoft.Windows.AppNotifications.Builder;
using Microsoft.Windows.AppNotifications;
using MyMediaCollection.Views;
namespace MyMediaCollection.Helpers
{
public class ToastWithAvatar
{
public const int ScenarioId = 1;
public const string ScenarioName = "Local Toast with Image";
public static bool SendToast()
{
var appNotification = new AppNotificationBuilder()
.AddArgument("action", "ToastClick")
.AddArgument(NotificationShared.scenarioTag, ScenarioId.ToString())
.SetAppLogoOverride(new System.Uri($"file://{App.GetFullPathToAsset("Square150x150Logo.scale-200.png")}"), AppNotificationImageCrop.Circle)
.AddText(ScenarioName)
.AddText("This is a notification message.")
.AddButton(new AppNotificationButton("Open App")
.AddArgument("action", "OpenApp")
.AddArgument(NotificationShared.scenarioTag, ScenarioId.ToString()))
.BuildNotification();
AppNotificationManager.Default.Show(appNotification);
// If notification is sent, it will have an Id. Success.
return appNotification.Id != 0;
}
public static void NotificationReceived(AppNotificationActivatedEventArgs notificationActivatedEventArgs)
{
var notification = new NotificationShared.Notification
{
Originator = ScenarioName,
Action = notificationActivatedEventArgs.Arguments["action"]
};
MainPage.Current.NotificationReceived(notification);
App.ToForeground();
}
}
}