Search code examples
c#wpfwindows-10toast.net-4.8

Window Toast notification with WPF .Net Framework 4.8 is empty on show


I installed the Microsoft.Toolkit.Uwp.Notifications NuGet package as by this instructions: https://learn.microsoft.com/en-us/windows/apps/design/shell/tiles-and-notifications/send-local-toast?tabs=desktop

Now I made a test Toast and tried to show it by this way:

    public Toast()
    {
        ToastContentBuilder test = new ToastContentBuilder();
        test.AddHeader(Guid.NewGuid().ToString(),"my first notification!", "HeaderArgument");
        test.SetToastScenario(ToastScenario.Reminder);
        test.AddArgument("myKey", "myValue");
        test.AddText("This is a cool Toast!");
        test.AddInlineImage(new Uri("https://picsum.photos/360/202?image=883"));
        test.AddAppLogoOverride(new Uri("ms-appdata:///local/Andrew.jpg"), ToastGenericAppLogoCrop.Circle);

        test.Show(toast =>
        {
            toast.ExpirationTime = DateTime.Now.AddDays(2);
            toast.Group = "myApp";
        });
    }

But when it shows up the header is Dev-Debug with the message (roughly translated) "New notification!" When I click it, my app is activated, but the argument is empty. I registered the toast like this:

ToastNotificationManagerCompat.OnActivated += toastArgs =>
{
    ToastArguments args = ToastArguments.Parse(toastArgs.Argument);
    ValueSet userInput = toastArgs.UserInput;
    Current.Dispatcher.Invoke(delegate
    {
        MessageBox.Show("Toast activated. Args: " + toastArgs.Argument);
        ToastNotificationManagerCompat.History.RemoveGroup("myApp");
    });
};

The last part with removing the history group works fine... so the toast.Group is working, but the rest before isn't... someone an idea how to make this work?


Solution

  • someone an idea how to make this work?

    Try to remove the call to AddAppLogoOverride or specify an absolute path to the logo image, e.g.:

    test.AddAppLogoOverride(new Uri("C:\\...\\Andrew.png"), ToastGenericAppLogoCrop.Circle);
    

    ms-appdata is not supported in an unpackaged WPF app.