Send a local toast notification from C# apps - Windows apps (2022)

  • Article
  • 10 minutes to read

A toast notification is a message that your app can construct and deliver to your user while they are not currently inside your app.

Send a local toast notification from C# apps - Windows apps (1)

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. This quickstart uses local notifications, which are the simplest notification to implement. All types of apps (WPF, UWP, WinForms, console) can send notifications!

Important

If you're writing a C++ app, please see the C++ UWP or C++ WRL documentation.

Step 1: Install NuGet package

Within your Visual Studio solution, right click your project, click "Manage NuGet Packages..." and search for and install the Microsoft.Toolkit.Uwp.Notifications NuGet package version 7.0 or greater.

Important

.NET Framework desktop apps that still use packages.config must migrate to PackageReference, otherwise the Windows SDKs won't be referenced correctly. In your project, right-click on "References", and click "Migrate packages.config to PackageReference".

(Video) How to send local toast notifications from a WinForms app - MSIX Package

.NET Core 3.0 WPF apps must update to .NET Core 3.1, otherwise the APIs will be absent.

.NET apps must use one of the Windows TFMs, otherwise the toast sending and management APIs like Show() will be missing. Set your TFM to net6.0-windows10.0.17763.0 or later.

Our code sample will use this package. This package allows you to create toast notifications without using XML, and also allows desktop apps to send toasts.

Step 2: Send a toast

In Windows 10 and Windows 11, your toast notification content is described using an adaptive language that allows great flexibility with how your notification looks. For more information, see the toast content documentation.

We'll start with a simple text-based notification. Construct the notification content (using the Notifications library), and show the notification! Note that the namespace is Microsoft.Toolkit.Uwp.Notifications.

Send a local toast notification from C# apps - Windows apps (2)

// Requires Microsoft.Toolkit.Uwp.Notifications NuGet package version 7.0 or greaternew ToastContentBuilder() .AddArgument("action", "viewConversation") .AddArgument("conversationId", 9813) .AddText("Andrew sent you a picture") .AddText("Check this out, The Enchantments in Washington!") .Show(); // Not seeing the Show() method? Make sure you have version 7.0, and if you're using .NET 6 (or later), then your TFM must be net6.0-windows10.0.17763.0 or greater

Try running this code and you should see the notification appear!

Step 3: Handling activation

After showing a notification, you likely need to handle the user clicking the notification (whether that means bringing up specific content after the user clicks it, opening your app in general, or performing an action when the user clicks the notification).

The steps for handling activation differ for UWP, Desktop (MSIX), and Desktop (unpackaged) apps.

  • UWP
  • Desktop (MSIX)
  • Desktop (unpackaged)

When the user clicks your notification (or a button on the notification with foreground activation), your app's App.xaml.cs OnActivated will be invoked, and the arguments you added will be returned.

(Video) How to send local toast notifications from a WPF app - MSIX Package

App.xaml.cs

protected override void OnActivated(IActivatedEventArgs e){// Handle notification activationif (e is ToastNotificationActivatedEventArgs toastActivationArgs){ // Obtain the arguments from the notificationToastArguments args = ToastArguments.Parse(toastActivationArgs.Argument); // Obtain any user input (text boxes, menu selections) from the notification ValueSet userInput = toastActivationArgs.UserInput;// TODO: Show the corresponding content}}

Important

You must initialize your frame and activate your window just like your OnLaunched code. OnLaunched is NOT called if the user clicks on your toast, even if your app was closed and is launching for the first time. We often recommend combining OnLaunched and OnActivated into your own OnLaunchedOrActivated method since the same initialization needs to occur in both.

Step 4: Handling uninstallation

  • UWP
  • Desktop (MSIX)
  • Desktop (unpackaged)

You don't need to do anything! When UWP apps are uninstalled, all notifications and any other related resources are automatically cleaned up.

Adding images

You can add rich content to notifications. We'll add an inline image and a profile (app logo override) image.

Note

Images can be used from the app's package, the app's local storage, or from the web. As of the Fall Creators Update, web images can be up to 3 MB on normal connections and 1 MB on metered connections. On devices not yet running the Fall Creators Update, web images must be no larger than 200 KB.

Important

Http images are only supported in UWP/MSIX/sparse apps that have the internet capability in their manifest. desktop non-MSIX/sparse apps do not support http images; you must download the image to your local app data and reference it locally.

(Video) Toast Notification - Windows 10 Application

Send a local toast notification from C# apps - Windows apps (3)

// Construct the content and show the toast!new ToastContentBuilder() ... // Inline image .AddInlineImage(new Uri("https://picsum.photos/360/202?image=883")) // Profile (app logo override) image .AddAppLogoOverride(new Uri("ms-appdata:///local/Andrew.jpg"), ToastGenericAppLogoCrop.Circle) .Show();

Adding buttons and inputs

You can add buttons and inputs to make your notifications interactive. Buttons can launch your foreground app, a protocol, or your background task. We'll add a reply text box, a "Like" button, and a "View" button that opens the image.

Send a local toast notification from C# apps - Windows apps (4)

int conversationId = 384928;// Construct the contentnew ToastContentBuilder() .AddArgument("conversationId", conversationId) ... // Text box for replying .AddInputTextBox("tbReply", placeHolderContent: "Type a response") // Buttons .AddButton(new ToastButton() .SetContent("Reply") .AddArgument("action", "reply") .SetBackgroundActivation()) .AddButton(new ToastButton() .SetContent("Like") .AddArgument("action", "like") .SetBackgroundActivation()) .AddButton(new ToastButton() .SetContent("View") .AddArgument("action", "viewImage") .AddArgument("imageUrl", image.ToString())) .Show();

The activation of foreground buttons are handled in the same way as the main toast body (your App.xaml.cs OnActivated will be called).

Note that arguments added to the top-level toast (like conversation ID) will also be returned when the buttons are clicked, as long as buttons use the AddArgument API as seen above (if you custom assign arguments on a button, the top-level arguments won't be included).

Handling background activation

  • UWP
  • Desktop

When you specify background activation on your toast (or on a button inside the toast), your background task will be executed instead of activating your foreground app.

For more information on background tasks, please see Support your app with background tasks.

If you are targeting build 14393 or higher, you can use in-process background tasks, which greatly simplify things. Note that in-process background tasks will fail to run on older versions of Windows. We'll use an in-process background task in this code sample.

(Video) Toast Notification with Button | WPF (.NetFramework) | Visual Studio 2019 |

const string taskName = "ToastBackgroundTask";// If background task is already registered, do nothingif (BackgroundTaskRegistration.AllTasks.Any(i => i.Value.Name.Equals(taskName))) return;// Otherwise request accessBackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync();// Create the background taskBackgroundTaskBuilder builder = new BackgroundTaskBuilder(){Name = taskName};// Assign the toast action triggerbuilder.SetTrigger(new ToastNotificationActionTrigger());// And register the taskBackgroundTaskRegistration registration = builder.Register();

Then in your App.xaml.cs, override the OnBackgroundActivated method. You can then retrieve the pre-defined arguments and user input, similar to the foreground activation.

App.xaml.cs

protected override async void OnBackgroundActivated(BackgroundActivatedEventArgs args){var deferral = args.TaskInstance.GetDeferral();switch (args.TaskInstance.Task.Name){case "ToastBackgroundTask":var details = args.TaskInstance.TriggerDetails as ToastNotificationActionTriggerDetail; if (details != null) { ToastArguments arguments = ToastArguments.Parse(details.Argument); var userInput = details.UserInput; // Perform tasks }break;}deferral.Complete();}

Set an expiration time

In Windows 10, all toast notifications go in Action Center after they are dismissed or ignored by the user, so users can look at your notification after the popup is gone.

However, if the message in your notification is only relevant for a period of time, you should set an expiration time on the toast notification so the users do not see stale information from your app. For example, if a promotion is only valid for 12 hours, set the expiration time to 12 hours. In the code below, we set the expiration time to be 2 days.

Note

The default and maximum expiration time for local toast notifications is 3 days.

// Create toast content and show the toast!new ToastContentBuilder() .AddText("Expires in 2 days...") .Show(toast => { toast.ExpirationTime = DateTime.Now.AddDays(2); });

Provide a primary key for your toast

If you want to programmatically remove or replace the notification you send, you need to use the Tag property (and optionally the Group property) to provide a primary key for your notification. Then, you can use this primary key in the future to remove or replace the notification.

To see more details on replacing/removing already delivered toast notifications, please see Quickstart: Managing toast notifications in action center (XAML).

Tag and Group combined act as a composite primary key. Group is the more generic identifier, where you can assign groups like "wallPosts", "messages", "friendRequests", etc. And then Tag should uniquely identify the notification itself from within the group. By using a generic group, you can then remove all notifications from that group by using the RemoveGroup API.

// Create toast content and show the toast!new ToastContentBuilder() .AddText("New post on your wall!") .Show(toast => { toast.Tag = "18365"; toast.Group = "wallPosts"; });

Clear your notifications

Apps are responsible for removing and clearing their own notifications. When your app is launched, we do NOT automatically clear your notifications.

(Video) How to send local toast notifications from a WPF app - Classic Win32 setup (Wix)

Windows will only automatically remove a notification if the user explicitly clicks the notification.

Here's an example of what a messaging app should do…

  1. User receives multiple toasts about new messages in a conversation
  2. User taps one of those toasts to open the conversation
  3. The app opens the conversation and then clears all toasts for that conversation (by using RemoveGroup on the app-supplied group for that conversation)
  4. User's Action Center now properly reflects the notification state, since there are no stale notifications for that conversation left in Action Center.

To learn about clearing all notifications or removing specific notifications, see Quickstart: Managing toast notifications in action center (XAML).

ToastNotificationManagerCompat.History.Clear();

Resources

FAQs

How do I show toast notifications in Winforms app? ›

To see toasts in action, launch our "Outlook Inspired App" demo and wait for it to load its notifications.
...
These toasts are just like system notifications:
  1. Toasts appear even if the associated application is closed.
  2. Toasts can be accessed from the Action Center.
  3. Toasts use the same color scheme as the operating system.
10 Feb 2020

How do I get custom toast notifications in Windows 10? ›

Enabling Toast Notifications in Windows 10
  1. In the system tray, click the notifications icon and All Settings.
  2. In the Settings screen, click System and Notifications & actions.
  3. Under the Notifications section, set the Show app notifications setting to On.

How do I make toast notifications? ›

You can display the toast notification with show() , as shown in the following example: Context context = getApplicationContext(); CharSequence text = "Hello toast!"; int duration = Toast.

What is Windows toast notification? ›

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.

How do you send a toast message? ›

Android Toast Example
  1. Toast toast=Toast. makeText(getApplicationContext(),"Hello Javatpoint",Toast. LENGTH_SHORT);
  2. toast. setMargin(50,50);
  3. toast. show();

How do I create a Windows notification? ›

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.

Is Toast a notification? ›

Google adopted the concepts of notification drawer and toast popup messages for user notifications as basic components of its Android operating system.

How do I set up alerts in Windows 10? ›

Manage notifications Windows 10: Select Start > Settings > System > Notifications & actions. Manage notifications MacOS: Select Apple menu > System Preferences > Notifications. Manage notifications Android: Select your phone's Settings app > Apps & Notifications>

What is toast notification in SCCM? ›

Description. The Windows 10 Toast Notification Script enables you to create nice and nifty toast notifications for the logged on user in Windows 10. This can be done with Configuration Manager, Microsoft Intune and scheduled tasks.

What is delivery toast message? ›

What is Toast in Android? A Toast is a feedback message. It takes a very little space for displaying while overall activity is interactive and visible to the user. It disappears after a few seconds. It disappears automatically.

Why is it called a toast message? ›

Mobile OS developers such as Android and iOS wanted to provide notifications to the users. The thing popped up from the bottom of the screen, a motion which was very similar of a toast popping up from the toaster when ready — so toast it was called.

How do you use the toast source app? ›

Select "Toast Source" from the system settings menu, then enable "Allow display over other apps." From there, hit your back button twice to go back to the app and continue enabling the rest of the toggles.

What is PC toast? ›

Wikipedia defines a Toast in the computing context as: A toast is a small, informational window displayed by certain kinds of software, especially instant messaging clients such as AOL Instant Messenger, Windows Live Messenger, XFire and Trillian.

How do I turn off toast notifications in Windows 10? ›

Turn On or Off Toast Notifications in for Windows 10 Apps

msc and navigate to User Configuration > Administrative Templates > Start Menu and Taskbar > Notifications. Now in the right side pane, you will see options to: Turn off notifications of network usage. Turn off Toast notifications on the lock screen.

What is banner notification in Microsoft teams? ›

Banner notifications are larger notifications which appear at the corner of your screen whenever you're mentioned individually or as a team in any channel/group. You'll also get a banner notification when someone messages you personally.

How long should a toast notification last? ›

It is recommended that Toast Notifications are transient and stay on the screen for eight seconds so that the user has time to read the message without it blocking information on the page for an extended amount of time.

How long does toast notification last? ›

Also, toasts will typically display for 2-5 seconds. A time frame of 3 seconds is ideal for most users. However, you can adjust the toast's exit timing to make it disappear quicker, so users don't have to wait.

What is a toast confirmation? ›

https://developer.android.com/reference/android/widget/Toast. Flags are used for confirmations, alerts, and acknowledgments that require minimal user interaction. These event-driven messages appear by overlaying content at the bottom left of the screen, emerging from the navigation sidebar.

How do I allow apps to send notifications? ›

Option 1: In your Settings app
  1. Open your phone's Settings app.
  2. Tap Notifications. App settings.
  3. Under "Most recent," find apps that recently sent you notifications. To find more apps, in the dropdown menu, tap All apps.
  4. Tap the app.
  5. Turn the app's notifications on or off.

How do I enable Windows app notifications? ›

Go to Settings > System > Notifications & actions‌ , under Get notifications from these senders select the app, and then under Priority of notifications in action center select Top.

How do I add an app to Windows notification? ›

Customize Quick Actions
  1. Click the Action Center icon.
  2. Choose All settings.
  3. Click System. Display, notifications, app, and power settings appear.
  4. Choose Notifications & actions. Quick action and notification settings appear.
  5. Click Add or remove quick actions.
  6. Toggle an app on or off.

Where do you put toast notifications? ›

Placement. Follow these placement guidelines for Toast Notifications: Place them either top-center or top-right of the screen. If badging is being used, toasts should be placed underneath it.

What is the difference between toast and snackbar? ›

Snackbars contain a single line of text directly related to the operation performed. They may contain a text action, but no icons. Toasts (Android only) are primarily used for system messaging. They also display at the bottom of the screen, but may not be swiped off-screen.

What are the features that toast Cannot be done? ›

Toast cannot :

Be focused or clicked. This makes a huge inconvenience to visually impaired. Notify application about its current status, e.g. the callback of dismiss.

How do I control Windows notifications? ›

Change your action center settings at any time from the Settings app.
  1. Select Start , then select Settings .
  2. Select System > Notifications & actions.
  3. Do any of the following: Choose whether to see notifications on the lock screen. Turn tips, tricks, and suggestions about Windows on or off.

How do Windows notifications work? ›

Windows 10 displays notifications from apps and services at the lower-right corner of the screen. They fly out just above the system tray. You'll get notifications about installed apps, new emails, system updates, and other events.

How much RAM can a 32 bit Windows 10 use? ›

All 32-bit versions of Windows 10 have a 4GB RAM limit.

How do I add notifications to react toast? ›

  1. Step 2: After installing the react-toastify module, now open your app. ...
  2. Step 3: Now import react-toastify module, toastify CSS file, and a caller method of toast notification.
  3. Step 4: In your app.js file, add this code to import the toastify-modules by adding the below code in your app.js.
26 Oct 2021

What is toast in Web design? ›

It is a small message that shows up in a box at the bottom of the screen and disappears on its own after few seconds. It is a simple feedback about an operation in which current activity remains visible and interactive.

How do I turn off software center notifications? ›

Software Center shows you the programs that are available for you to install.
...
Disabling Notifications
  1. Click the Start Menu.
  2. Open the Settings application.
  3. Go to System > Notifications & Actions.
  4. Scroll down until you see Software Center.
  5. Click the sliding toggle to turn Off notifications.

What does have a toast mean? ›

an expression of good wishes or respect for someone that involves holding up and then drinking from a glass of alcohol, especially wine, after a short speech: Now, if you'd all please raise your glasses, I'd like to propose a toast to the bride and groom.

How do you know if a text message was delivered? ›

Now when you send a text message you can tap and hold the message and select “View message details“. On some models, it may be under “View report“. The statuses will show “Received“, “Delivered“, or may simply show the time of delivery. If the message was not delivered, it may show as “Pending” or “None” status.

How do I turn off toast notifications? ›

How to Turn Off Or Disable Clipboard Toast Notification | Android 12

What makes a good toast? ›

The art of the toast lies in storytelling. But the key is to also make a point, so having a theme or thesis statement can help you write an engaging toast. Keep in mind that stories should have a beginning, middle, and end. And everything you include should build to your final words and prove that theme or thesis.

What is type of toasting? ›

Toasting bread to a desired crispness and putting butter on top is the general way to make toast. You can add cinnamon and sugar for cinnamon toast, jelly for some sweetness, peanut butter or Nutella. Use plain toast to spice up a ham sandwich. Toasted bread is also great for crunchy BLTs.

How do you make toast? ›

How to Make Toast
  1. Step 1: Cooking Bread. Place toast in toaster.
  2. Step 2: Select Temperature. Select temperature for desired crispiness.
  3. Step 3: Cooking Bread. Push down toaster lever to begin toasting.
  4. Step 4: Buttering Toast. After toast pops up remove from toaster, place on plate.
  5. Step 5: Apply Butter. ...
  6. Step 6: Final Step.

Is the toast app free? ›

Toast TakeOut is completely commission-free. Serve more, make more.

Can you use toast on your phone? ›

Installing the Toast App on your Android Mobile Device

Your Android mobile device can act as an emulator to view the Toast App in the event that you do not have access to a POS device. Emulators are helpful if you want to view your menus as they would appear to your staff or review other features of the Toast App.

How do you add notification in Android app explain with an example? ›

Create a Notification
  1. On this page.
  2. Add the support library.
  3. Create a basic notification. Set the notification content. Create a channel and set the importance. ...
  4. Add action buttons.
  5. Add a direct reply action. Add the reply button. ...
  6. Add a progress bar.
  7. Set a system-wide category.
  8. Show an urgent message.

What are popup notifications? ›

If you want the notifications to turn on the screen, go to Settings> Notifications> More notification settings and turn on the switch for Notifications turn on screen. - open WhatsApp, tap in the upper right corner, go to Settings > Notifications > Popup notification and select Always show popup.

What is the difference between Banner and feed notifications in Teams? ›

Selecting Banner and feed will send notifications to your device and to Activity at the top left of Teams. Selecting Only show in feed will skip sending notifications to your desktop and will only show up in your activity feed.

What is difference between Banner and feed in Teams? ›

If you select the “Banner” option, the banner notification will still show, but no email will be sent. If you select “Only show in feed” the notification will only be visible via the feed in the upper left of the application.

Are Microsoft team chats private? ›

Team channels are places where everyone on the team can have open conversations. Private chats are only visible to those people in the chat.

Where do you put toast notifications? ›

Placement. Follow these placement guidelines for Toast Notifications: Place them either top-center or top-right of the screen. If badging is being used, toasts should be placed underneath it.

How do I add notifications to react toast? ›

  1. Step 2: After installing the react-toastify module, now open your app. ...
  2. Step 3: Now import react-toastify module, toastify CSS file, and a caller method of toast notification.
  3. Step 4: In your app.js file, add this code to import the toastify-modules by adding the below code in your app.js.
26 Oct 2021

How do I create an HTML notification message? ›

If you want the ability to close the alert message, add a <span> element with an onclick attribute that says "when you click on me, hide my parent element" - which is the container <div> (class="alert"). Tip: Use the HTML entity " &times; " to create the letter "x".

How do I turn off toast notifications on Android? ›

How to Turn Off Or Disable Clipboard Toast Notification | Android 12

When should you not use toast notifications? ›

Toasts display brief, temporary notifications. They are noticeable but do not disrupt the user experience and do not require an action to be taken. Toasts should only be used for confirmations, simple notifications, and low-priority alerts that do not need to completely interrupt the user experience.

What is the difference between toast and snackbar? ›

Snackbars contain a single line of text directly related to the operation performed. They may contain a text action, but no icons. Toasts (Android only) are primarily used for system messaging. They also display at the bottom of the screen, but may not be swiped off-screen.

What is a toast component? ›

The toast component is a non-disruptive message that appears at the bottom of the interface to provide quick, at-a-glance feedback on the outcome of an action.

How do you make a custom toast in react? ›

Create Your Own Toast Component in React - YouTube

How does Toastify react work? ›

What is React-Toastify? React-Toastify is one of the top React toast libraries available. This tool allows you to add toast notifications to your application with ease and can also be used to set notifications and alerts. Use any of the commands below to install the React-Toastify package.

What is notification API? ›

The Notifications API lets a web page or app send notifications that are displayed outside the page at the system level; this lets web apps send information to a user even if the application is idle or in the background.

How do I send push notifications to my website? ›

Push Notifications on the Open Web
  1. Register a Service Worker.
  2. Set Up the Initial State.
  3. Make a Project on the Firebase Developer Console.
  4. Add a Web App Manifest.
  5. Subscribe to Push Messaging.
  6. Service Worker Push Event Listener.
  7. Sending a Push Message.
  8. A More Complete Push Event Example.
11 Mar 2015

How do you remove toast? ›

Removing Non-Toast-Approved Applications from a Toast Device
  1. Select the circular home button at the bottom of the device to access the Android home screen. ...
  2. Press and hold a non-Toast application icon on the screen.
  3. When prompted, drag the app to the top of the screen to Uninstall.
  4. Select Ok to confirm.

What does have a toast mean? ›

an expression of good wishes or respect for someone that involves holding up and then drinking from a glass of alcohol, especially wine, after a short speech: Now, if you'd all please raise your glasses, I'd like to propose a toast to the bride and groom.

What are the features that toast Cannot be done? ›

Toast cannot :

Be focused or clicked. This makes a huge inconvenience to visually impaired. Notify application about its current status, e.g. the callback of dismiss.

Videos

1. How to change Toast Notification in Windows 10
(Technical Ustad)
2. [English] Toast Notifications For universal application
(Egypt AppFactory)
3. Windows 10 Toast Notification in Visual Basic.Net
(Learning Code)
4. WPF Simple Toast Notifications Using Syles
(tips'n tricks)
5. Windows 10 Toast Notifications Desktop Application - C++
(Solutions Cloud)
6. 3. System Tray, Sound Notification | WPF C# Timer
(Quasimodo Programs)

Top Articles

Latest Posts

Article information

Author: Frankie Dare

Last Updated: 08/31/2022

Views: 6258

Rating: 4.2 / 5 (73 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Frankie Dare

Birthday: 2000-01-27

Address: Suite 313 45115 Caridad Freeway, Port Barabaraville, MS 66713

Phone: +3769542039359

Job: Sales Manager

Hobby: Baton twirling, Stand-up comedy, Leather crafting, Rugby, tabletop games, Jigsaw puzzles, Air sports

Introduction: My name is Frankie Dare, I am a funny, beautiful, proud, fair, pleasant, cheerful, enthusiastic person who loves writing and wants to share my knowledge and understanding with you.