We've got a Windows Forms Application (vs. WPF) that was originally created for Windows 7. We're carrying the product forward to be used in Windows 8.
Is it possible to show Windows 8 Toast Notifications (Windows.UI.Notifications namespace) from this WinForm app, for users running Windows 8?
I can't seem to find any examples. Everything I find is a WPF or Windows Store apps—no examples are WinForm apps.
A toast notification is a message that your app can construct and deliver to your user while they are not currently inside your app. This quickstart walks you through the steps to create, deliver, and display a Windows 10 or Windows 11 toast notification using rich content and interactive actions.
To send a text alert from a Toast POS device: 1. Select the overflow icon ( ⋮) on the top right corner of the device screen and select Send Text Alert.
To get started, head to Settings > System > Notifications & actions – or, if you're on a Windows 10 PC, click here to open notifications & actions. First, send notifications, reminders and alarms directly to the action center by right-clicking action center in your taskbar, then selecting Turn on quiet hours.
It is possible to use toast notification in winform poject under win 8. I create a winform project, add a button, when pressing the button, there will be a toast notification showed in the right-top of the window. The following is what I have done.
In the desktop projects the Core tab doesn’t appear by default. You can add the Windows Runtime by right click the project in Solution Explore, choosing Unload Project, adding the following snippet, and re-opening the project (right click project choose Reload Project). When you open the Reference Manager dialog box, the Core tab appears. Then you can add "Windows" reference to the project.
<PropertyGroup>
<TargetPlatformVersion>8.0</TargetPlatformVersion>
</PropertyGroup>
For more details you can refer to this link(near to the end part of the page)
Manually add the dll in "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\Facades\System.Runtime.dll" (right click Reference, add Reference, Browse)
This parts of codes you can refer to this link Notes: if you only want to show toast notification, you don't need to care about ShellHelpers.cs. Or if you like, you can just copy the codes below.You may need to add some usings accordingly, and there maybe a picture, if don't have, it can still run. Oh, you also need to set a APP_ID (just a const string to represent uniqueness).
private const String APP_ID = "Microsoft.Samples.DesktopToastsSample";
using Windows.UI.Notifications;
using Windows.Data.Xml.Dom;
using System.IO;
// Get a toast XML template
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText04);
// Fill in the text elements
Windows.Data.Xml.Dom.XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
for (int i = 0; i < stringElements.Length; i++)
{
stringElements[i].AppendChild(toastXml.CreateTextNode("Line " + i));
}
// Specify the absolute path to an image
String imagePath = "file:///" + Path.GetFullPath("toastImageAndText.png");
Windows.Data.Xml.Dom.XmlNodeList imageElements = toastXml.GetElementsByTagName("image");
imageElements[0].Attributes.GetNamedItem("src").NodeValue = imagePath;
// Create the toast and attach event listeners
ToastNotification toast = new ToastNotification(toastXml);
//toast.Activated += ToastActivated;
//toast.Dismissed += ToastDismissed;
//toast.Failed += ToastFailed;
// Show the toast. Be sure to specify the AppUserModelId on your application's shortcut!
ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast);
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