Search code examples
c#wpfwindows-8notificationstoast

C# ToastNotification in Windows 8. ExpirationTime is not working


I am working with the ToastNotification object in Windows 8 and they work fine.

The only attribute that seems to have problems is ExpirationTime that should set the moment when the message fades away if it is not clicked by a user.

ToastNotification toast = new ToastNotification(toastXml);

toast.ExpirationTime = DateTimeOffset.Now.AddDays(1); ;
toast.Activated += ToastActivated;
toast.Dismissed += ToastDismissed;

ToastNotificationManager.CreateToastNotifier(APP_ID).Show(toast);

I have tried as well as the example in the code that i post:

toast.ExpirationTime =  System.DateTime.Today.AddDays(1)
toast.ExpirationTime = new DateTimeOffset(DateTime.Now.AddDays(1));

But it does not work. The toast message shows correctly but it disappears after a few seconds later.

What am i doing wrong?


Solution

  • I found an answer to my own question. I post it, it might be usefull to someone in future.

    enter image description here

    The really ExpirationTime used is the "show notification for" setted in the Pc Settings. The ExpirationTime that you set in the code can't exceed this value.