MacakM
MacakM

Reputation: 1820

UWP global MessageDialog on desktop

I would like to have an application which alerts the user when some event occurs.

I use a MessageDialog, but the problem is that is pops out only when the application is on the top of a screen (when user for example browses the web, he wouldn't be alerted, he would have to click on my app to see the alert)

Is there some alternative I can use for this case or UWP does not support this behaviour?

Upvotes: 2

Views: 78

Answers (1)

Jessica
Jessica

Reputation: 2067

You should try toast notifications. The following two nuget packages need to be installed first.

Install-Package QueryString.NET -Version 1.0.0

Install-Package Microsoft.Toolkit.Uwp.Notifications

private void Toast()
{
    var visual = new ToastVisual
    {
        BindingGeneric = new ToastBindingGeneric
        {
            Children =
            {
                new AdaptiveText
                {
                    Text = "title"
                },

                new AdaptiveText
                {
                    Text = "content"
                }
            }
        }
    };

    var toastContent = new ToastContent
    {
        Visual = visual,

        Launch = new QueryString
        {
            { "action", "viewConversation" },
            { "conversationId", "id" }

        }.ToString()
    };

    var toast = new ToastNotification(toastContent.GetXml());
    ToastNotificationManager.CreateToastNotifier().Show(toast);
}

enter image description here

Upvotes: 3

Related Questions