Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
472 views
in Technique[技术] by (71.8m points)

c# - Unexpected behaviours in toast notification from desktop app in Windows 10

I used the toast notifications for desktop app since Windows 8.1 but with the new action center in Windows 10, I am experiencing some unexpected behaviours.

When the user do nothing with the toast, it simply disappear without going to the action center (ToastNotification.Dismissed is ToastDismissalReason.TimedOut). I don't know if it related to the fact that I use it in a win32 app but the same toast in a Windows Universal App goes to the action center when it timed out.

One thing to note is that I have not registered an AppUserModelID for my win32 app like it was needed in W8.1, it seems to not be mandatory anymore. I still tested with a registered id, and I had the same popblem.

So, how can i prevent the toast from not going in the action center when it timed out ?

Here is a minimalist code (console app) that reproduces the issue :

using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;

namespace ToastDesktop
{
    internal class Program
    {
        /// Add in the .csproj in the <PropertyGroup/> where <TargetFrameworkVersion/> is:
        /// <TargetPlatformVersion>10.0.10240.0</TargetPlatformVersion>
        ///
        /// Reference to add :
        /// - Windows.UI
        /// - Windows.Data
        private static void Main(string[] args)
        {
            string xml = $@"
                <toast>
                    <visual>
                        <binding template='ToastGeneric'>
                            <text>Some title</text>
                            <text>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</text>
                        </binding>
                    </visual>
                </toast>";

            XmlDocument doc = new XmlDocument();
            doc.LoadXml(xml);

            ToastNotification toast = new ToastNotification(doc);
            toast.Tag = "tag";
            toast.Group = "group";

            ToastNotificationManager.CreateToastNotifier("ToastDesktop").Show(toast);
        }
    }
}

Thanks for your help.

Edit : I posted this bug on the msdn blog post that cover the subject and I got the confirmation that it should remain in the action center when timed out and that it might be a bug.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Win32 apps need to set up a COM server in order to have toasts persisted in Action Center: http://blogs.msdn.com/b/tiles_and_toasts/archive/2015/10/15/quickstart-handling-toast-activations-from-win32-apps-in-windows-10.aspx


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...