-
Notifications
You must be signed in to change notification settings - Fork 1.4k
ToastNotificationManagerCompat Remove by Tag #4429
-
I am running a WinUI3 unpackaged desktop application so I am using the ToastNotificationManagerCompat
class. I am wondering how to remove a Toast Notification by Tag. Per the documentation at https://docs.microsoft.com/windows/apps/design/shell/tiles-and-notifications/send-local-toast#step-7-remove-and-manage-notifications I should be able to call
DesktopNotificationManagerCompat.History.Remove("Message2");
However, when I do this I am getting this exception
System.Exception
HResult=0x80131500
Message=You must call RegisterAumidAndComServer first.
Source=Microsoft.Toolkit.Uwp.Notifications
StackTrace:
at Microsoft.Toolkit.Uwp.Notifications.DesktopNotificationManagerCompat.EnsureRegistered()
at Microsoft.Toolkit.Uwp.Notifications.DesktopNotificationManagerCompat.get_History()
at DCF.Forms.Core.UWPNotificationsWrapper.RemoveToastNotificationByTag(String tag) in D:\Workspace\Stash\dcf_forms2\src\DCF.Forms.Core\UWPNotificationsWrapper.cs:line 62
at DCF.Forms.Core.UXFormToasterNotificationWindows.RemoveToastNotificationToastGuid(Guid toastGuid) in D:\Workspace\Stash\dcf_forms2\src\DCF.Forms.Core\UXFormToasterNotificationWindows.cs:line 252
at DCF.UX.FormsSandboxApp.NotificationTester.Plugin.NotificationTesterPlugin.b__8_9() in D:\Workspace\Stash\dcf_forms2\samples\FormsSandboxApp\src\DCF.UX.FormsSandboxApp.NotificationTester.Plugin\NotificationTesterPlugin.cs:line 140
at Microsoft.Toolkit.Mvvm.Input.RelayCommand.Execute(Object parameter)
at ABI.System.Windows.Input.ICommand.Vftbl.Do_Abi_Execute_3(IntPtr thisPtr, IntPtr parameter)
I also see that the DesktopNotificationManagerCompat is marked obsolete. Should I be doing this a different way?
Beta Was this translation helpful? Give feedback.
All reactions
Hi @Daniellled, yes, that class is obsolete and the replacement class is ToastNotificationManagerCompat. Here's the docs for using it: https://docs.microsoft.com/windows/apps/design/shell/tiles-and-notifications/send-local-toast?tabs=desktop
(It looks like you were also using some unofficial staging docs rather than docs.microsoft.com as linked above)
ToastNotificationManagerCompat will work fully from unpackaged apps :)
And if you want an example of how to handle toast activation from a WinUI 3 app, we have toasts functioning in the Windows App SDK Gallery app, here's the source for that: https://github.com/andrewleader/WindowsAppSDKGallery/blob/main/WindowsAppSDKGallery/App.xaml.cs#L60
Replies: 2 comments 4 replies
-
Hi @Daniellled, thanks for reporting this. Could you open an issue so we can properly track and fix this?
Beta Was this translation helpful? Give feedback.
All reactions
-
FYI @andrewleader
Beta Was this translation helpful? Give feedback.
All reactions
-
Hi @Daniellled, yes, that class is obsolete and the replacement class is ToastNotificationManagerCompat. Here's the docs for using it: https://docs.microsoft.com/windows/apps/design/shell/tiles-and-notifications/send-local-toast?tabs=desktop
(It looks like you were also using some unofficial staging docs rather than docs.microsoft.com as linked above)
ToastNotificationManagerCompat will work fully from unpackaged apps :)
And if you want an example of how to handle toast activation from a WinUI 3 app, we have toasts functioning in the Windows App SDK Gallery app, here's the source for that: https://github.com/andrewleader/WindowsAppSDKGallery/blob/main/WindowsAppSDKGallery/App.xaml.cs#L60
Beta Was this translation helpful? Give feedback.
All reactions
-
@Arlodotexe - Sure I will open an issue.
@andrewleader - Wow I didn't notice I was using some unofficial staging docs. Thank you for the updated link and samples.
Beta Was this translation helpful? Give feedback.
All reactions
-
@Daniellled there's no need to open an issue. The API you're using is supposed to throw that exception, you're supposed to be using the ToastNotificationManagerCompat API instead of DesktopNotificationManagerCompat.
Beta Was this translation helpful? Give feedback.
All reactions
-
Could you please have a look at the following two posts, because a scheduled notification with WinAppSDK does not work!
- Scheduling of local windows notification not possible? microsoft/WindowsAppSDK#5046 (reply in thread)
- Local notification for Windows dotnet/maui#27092 (comment)
Thanks
pc
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1