Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ToastNotificationManagerCompat Remove by Tag #4429

Discussion options

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?

You must be logged in to vote

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

Comment options

Hi @Daniellled, thanks for reporting this. Could you open an issue so we can properly track and fix this?

You must be logged in to vote
1 reply
Comment options

Comment options

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

You must be logged in to vote
3 replies
Comment options

@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.

Comment options

@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.

Comment options

Hi @andrewleader

Could you please have a look at the following two posts, because a scheduled notification with WinAppSDK does not work!

Thanks
pc

Answer selected by andrewleader
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

AltStyle によって変換されたページ (->オリジナル) /