mirror of
https://github.com/PacktPublishing/Learn-WinUI-3-Second-Edition.git
synced 2026-06-20 12:23:09 +00:00
Chapter 14 samples
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user