/**
         * Removes the notification for the specified game id, unless we have never shown one.
         */
        public static void HideInviteNotification(string id)
        {
            if (!inviteToasts.ContainsKey(id))
            {
                return;
            }
            var toast = inviteToasts[id];

            inviteToasts.Remove(id);

            // Each one of these might throw if the user interacted with them.
            try { NOTIFIER.Hide(toast); } catch { /* ignored */ }
            try { ToastNotificationManager.History.Remove(toast.Tag); } catch { /* ignored */ }
        }
        internal void SendCompletedToast(string FileName)
        {
            ToastContent toastContent = new ToastContent()
            {
                Visual = new ToastVisual()
                {
                    BindingGeneric = new ToastBindingGeneric()
                    {
                        Children =
                        {
                            new AdaptiveText()
                            {
                                Text = "Download completed!"
                            },

                            new AdaptiveText()
                            {
                                Text = FileName
                            }
                        }
                    }
                }
            };

            ToastNotification notification = new ToastNotification(toastContent.GetXml())
            {
                Tag = toastNotification.Tag
            };

            toastNotifier.Hide(toastNotification);
            toastNotifier.Show(notification);
        }
 public static void ToastHideOnDismiss(ToastNotifier notifier, ToastNotification sender, ToastDismissedEventArgs args)
 {
     if (args.Reason == ToastDismissalReason.UserCanceled || args.Reason == ToastDismissalReason.TimedOut)
     {
         notifier.Hide(sender);
     }
 }
Exemple #4
0
        public static void CreateToast(String xml)
        {
            if (!ExecutionMode.IsRunningAsUwp())
            {
                return;
            }

            try
            {
                if (notifier == null)
                {
                    notifier = ToastNotificationManager.CreateToastNotifier();
                }
                else
                {
                    notifier.Hide(toast);
                }
                XmlDocument toastXml = new XmlDocument();
                toastXml.LoadXml(xml);

                toast = new ToastNotification(toastXml);
                notifier.Show(toast);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("CreateToast Error:" + ex.Message);
            }
        }
        /// <summary>
        /// Hides the specified toast notification from the screen (moves it into Action Center).
        /// </summary>
        /// <param name="notification">The object that specifies the toast to hide.</param>
        public void Hide(ToastNotification notification)
        {
#if WIN32
            PreprocessToast(notification);
#endif

            _notifier.Hide(notification);
        }
Exemple #6
0
 public static void HideToast()
 {
     Helper.Print("hide toast");
     foreach (var e in CurrentToastMap)
     {
         try
         {
             Notifier.Hide(e.Value);
             Helper.Print("hide toast, music: {0}, state: {1}", e.Key.Music.Name, e.Key.State);
         }
         catch (Exception)
         {
             // 通知已经隐藏。
         }
     }
     CurrentToastMap.Clear();
 }
        private void ShowToastNotification(string title, string stringContent)
        {
            if (_lastToast != null)
            {
                _toastNotifier.Hide(_lastToast);
            }
            Windows.Data.Xml.Dom.XmlDocument toastXml      = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
            Windows.Data.Xml.Dom.XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text");
            toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode(title));
            toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode(stringContent));
            Windows.Data.Xml.Dom.IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
            //Windows.Data.Xml.Dom.XmlElement audio = toastXml.CreateElement("audio");
            //audio.SetAttribute("src", "ms-winsoundevent:Notification.SMS");

            ToastNotification toast = new ToastNotification(toastXml);

            toast.ExpirationTime = DateTime.Now.AddSeconds(5);
            _toastNotifier.Show(toast);
            _lastToast = toast;
        }
Exemple #8
0
 protected override void OnBackKeyPress(CancelEventArgs e)
 {
     if (vm.BackButtonPressed())
     {
         e.Cancel = true;
         return;
     }
     else if (toast == null)
     {
         toast            = SimpleToastNotification("Please press BACK again to Leave the Game");
         toast.Dismissed += (sender, args) =>
         {
             toast = null;
         };
         toaster.Show(toast);
         e.Cancel = true;
         return;
     }
     toaster.Hide(toast);
     toast = null;
     base.OnBackKeyPress(e);
 }
Exemple #9
0
        /// <summary>
        /// 通知センターに通知を送ります
        /// </summary>
        /// <param name="imagePath"></param>
        /// <param name="caption"></param>
        /// <param name="text"></param>
        /// <param name="silent"></param>
        private void Notify(string imagePath, string caption, string text, bool silent = true)
        {
            var template = ToastTemplateType.ToastImageAndText02;
            var xml      = ToastNotificationManager.GetTemplateContent(template);

            // 画像をセット
            var images = xml.GetElementsByTagName("image");
            var src    = images[0].Attributes.GetNamedItem("src");

            if (src != null)
            {
                src.InnerText = imagePath;
            }

            // テキストをセット
            var texts = xml.GetElementsByTagName("text");

            texts[0].AppendChild(xml.CreateTextNode(caption));
            texts[1].AppendChild(xml.CreateTextNode(text));

            // 音を消す
            if (silent)
            {
                var audio = xml.CreateElement("audio");
                audio.SetAttribute("silent", "true");
                xml.GetElementsByTagName("toast")[0].AppendChild(audio);
            }

            // 前の通知があったら隠す
            if (_lastNotification != null)
            {
                _notifier.Hide(_lastNotification);
            }

            // 通知
            _lastNotification = new ToastNotification(xml);
            _notifier.Show(_lastNotification);
        }
Exemple #10
0
        private async void ShowNotification_OnClick(object sender, RoutedEventArgs e)
        {
            Task.Run(async() =>
            {
                var uri             = new Uri("ms-appx:///Assets/StoreSolo.png");
                var toastCollection = new ToastCollection(ToastCollectionId, "ContosoInc", "Args", uri);

                await ToastNotificationManager.GetDefault().GetToastCollectionManager().SaveToastCollectionAsync(toastCollection);

                _toastNotifierManager = await ToastNotificationManager.GetDefault().GetToastNotifierForToastCollectionIdAsync(ToastCollectionId);

                var toastsHistory = ToastNotificationManager.History.GetHistory().ToList();

                foreach (var toast in toastsHistory)
                {
                    lock (_toastNotifierManager)
                    {
                        _toastNotifierManager.Hide(toast);
                    }
                }

                await ShowDownloadNotification("status", 2, "tag");
            });
        }