I'm trying to display Windows 10 Toasts with my WPF C# Desktop application.
Sadly the API and general support concerning Windows 10 notifications in non-UWP or Store apps seems pretty limited and chaotic. Lately the UWP Community Toolkit was published, which seems to try and make things easier for us. There's also this Store app, Notifications Visualizer, which helps in making Toasts like this:
I went on and tried to generated the Toast using C# and the API provided by the UWP Community Toolkit.
using Microsoft.Toolkit.Uwp.Notifications;
ToastContent toastContent = new ToastContent()
{
Visual = new ToastVisual()
{
BindingGeneric = new ToastBindingGeneric()
{
Children =
{
new AdaptiveText()
{
Text = "Matt sent you a friend request"
},
new AdaptiveText()
{
Text = "Hey, wanna dress up as wizards and ride around on our hoverboards together?"
}
},
AppLogoOverride = new ToastGenericAppLogo()
{
Source = "https://unsplash.it/64?image=1005",
HintCrop = ToastGenericAppLogoCrop.Circle
}
}
}
};
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(toastContent.GetContent());
var toast = new ToastNotification(xmlDoc);
ToastNotificationManager.CreateToastNotifier(AppId).Show(toast); // Display toast
Unfortunately, no matter what I try, I seem to be unable to get the same result, the Image is always missing for some reason:
Most information I found concerning these notifications are either outdated or useless. Can someone please shed some light on this? Thank you.
It looks like with .NET Standard this can only be achieved in two steps, and one of them is out of the scope of the UWP Toolkit.
.NET Standard Apps require a COM Server and a special Start Menu Shortcut to properly use the Windows 10 Action Center. UWP Apps seem to not require or already come with an equivalent functionality. These two steps are supposed to be performed during application installation, and this is obviously something the Microsoft UWP Toolkit takes no part in. Thus the UWP Toolkit alone is not only unable but never will be able to provide a complete solution for displaying Windows 10 Toasts for .NET Standard in a self contained way.
I found an obscure C# Project on Github that has 'Microsoft' in its name, it works out of the box without the UWP Toolkit. It requires you to provide a GUID and an AppID string which then is used to register the COM Server and create the Shortcut.
A cleaner looking alternative is this library which seems to provide the same functionality. I still have to test it.
Both these solutions should work with Microsoft's NotificationsExtensions librabry, which is a precursor of the UWP Toolkit and helps with generating the XML code Toasts are made of.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With