Home

Awesome

Desktop Toast

A library for toast notifications from desktop app. This library will, if necessary, install a shortcut in Windows startup and show a toast asynchronously.

Requirements

Contents

Note

Usage

Instantiate ToastRequest class, set its properties and then call ToastManager.ShowAsync method.

public async Task<bool> ShowToastAsync()
{
    var request = new ToastRequest
    {
        ToastTitle = "DesktopToast WPF Sample",
        ToastBody = "This is a toast test.",
        ToastLogoFilePath = string.Format("file:///{0}", Path.GetFullPath("toast128.png")),
        ShortcutFileName = "DesktopToast.Wpf.lnk",
        ShortcutTargetFilePath = Assembly.GetExecutingAssembly().Location,
        AppId = "DesktopToast.Wpf",
    };

    var result = await ToastManager.ShowAsync(request);

    return (result == ToastResult.Activated);
}

ToastRequest class is a container of information necessary for installing a shortcut and showing a toast. It has the following properties:

PropertyDescriptionNote
ToastTitleToast titleOptional
ToastBodyToast bodyRequired for toast
ToastBodyListToast body list (If specified, toast body will be substituted by this list.)Optional
ToastLogoFilePathLogo image file path of toastOptional
ToastAudioAudio type of toastOptional
ToastXmlXML representation of Toast (If specified, this XML will be used for a toast as it is.)Optional
ShortcutFileNameShortcut file name to be installed in Windows startupRequired for shortcut
ShortcutTargetFilePathTarget file path of shortcutRequired for shortcut
ShortcutArgumentsArguments of shortcutOptional
ShortcutCommentComment of shortcutOptional
ShortcutWorkingFolderWorking folder of shortcutOptional
ShortcutWindowStateWindow state of shortcutOptional
ShortcutIconFilePathIcon file path of shortcutOptional
AppIdAppUserModelID of applicationRequired
ActivatorIdAppUserModelToastActivatorCLSID of application (for Action Center of Windows 10)Optional
WaitingDurationWaiting duration before showing a toast after the shortcut file is installedOptional

Action Center of Windows 10

To interact with Action Center of Windows 10, an application needs to register COM class type which implements INotificationActivationCallback. In addition, the registration of COM server in the registry is required for an application to be started by COM when it is not running.

See WPF sample for implementation. Note that the CLSID of COM class type (AppUserModelToastActivatorCLSID) must be unique for each application.

Also check the following sample.

Interactive toast of Windows 10

To show an interactive toast of Windows 10, prepare a XML representation of toast and set it to ToastXml property. Check the following article.

You can compose it from scratch or utilize NotificationsExtensions.Win10 library. See WPF sample.

License