Пример #1
0
        public static void NotifyNewApplication()
        {
            // Construct the visuals of the toast
            var toastContent = new ToastContent()
            {
                // Arguments when the user taps body of toast
                Launch = new QueryString()
                {
                    { "action", "ok" },
                    { "appidrevision", $"newapp" },
                }.ToString(),

                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        Children =
                        {
                            new AdaptiveText()
                            {
                                Text = _settings.ToastNotifyNewApplicationSettings.Title,
                            },

                            new AdaptiveText()
                            {
                                Text = _settings.ToastNotifyNewApplicationSettings.SubText,
                            },
                        },
                    },
                },

                Actions = new ToastActionsCustom()
                {
                    Buttons =
                    {
                        // Note that there's no reason to specify background activation, since our COM
                        // activator decides whether to process in background or launch foreground window
                        new ToastButton(_settings.ToastNotifyNewApplicationSettings.BtSchedule, new QueryString()
                        {
                            { "action",                                                         "schedule" },
                            { "appidrevision",                                                  $"newapp"  },
                        }.ToString()),

                        new ToastButton(_settings.ToastNotifyNewApplicationSettings.BtPostpone, new QueryString()
                        {
                            { "action",                                                         "postpone" },
                            { "appidrevision",                                                  $"newapp"  },
                        }.ToString()),
                    },
                },

                Scenario = (ToastScenario)_settings.ToastNotifyNewApplicationSettings.ToastScenario,
            };

            var doc = new XmlDocument();

            doc.LoadXml(toastContent.GetContent());

            // And create the toast notification
            var toast = new ToastNotification(doc)
            {
                ExpirationTime = DateTimeOffset.Now.AddSeconds(_settings.ToastNotifyNewApplicationSettings.Duration)
            };

            // And then show it
            DesktopNotificationManagerCompat.CreateToastNotifier().Show(toast);
        }