當前位置: 首頁>>代碼示例>>C#>>正文


C# Notifications.ToastNotification類代碼示例

本文整理匯總了C#中Windows.UI.Notifications.ToastNotification的典型用法代碼示例。如果您正苦於以下問題:C# ToastNotification類的具體用法?C# ToastNotification怎麽用?C# ToastNotification使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ToastNotification類屬於Windows.UI.Notifications命名空間,在下文中一共展示了ToastNotification類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: OnSendNotification

        private void OnSendNotification(object sender, RoutedEventArgs e)
        {
            string xml = @"<toast launch=""developer-defined-string"">
                          <visual>
                            <binding template=""ToastGeneric"">
                              <image placement=""appLogoOverride"" src=""Assets/MicrosoftLogo.png"" />
                              <text>DotNet Spain Conference</text>
                              <text>How much do you like my session?</text>
                            </binding>
                          </visual>
                          <actions>
                            <input id=""rating"" type=""selection"" defaultInput=""5"" >
                          <selection id=""1"" content=""1 (Not very much)"" />
                          <selection id=""2"" content=""2"" />
                          <selection id=""3"" content=""3"" />
                          <selection id=""4"" content=""4"" />
                          <selection id=""5"" content=""5 (A lot!)"" />
                            </input>
                            <action activationType=""background"" content=""Vote"" arguments=""vote"" />
                          </actions>
                        </toast>";

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

            ToastNotification toast = new ToastNotification(doc);
            ToastNotificationManager.CreateToastNotifier().Show(toast);

        }
開發者ID:qmatteoq,項目名稱:dotNetSpainConference2016,代碼行數:29,代碼來源:MainPage.xaml.cs

示例2: InvokeSimpleToast

        void InvokeSimpleToast(string messageReceived)
        {
            // GetTemplateContent returns a Windows.Data.Xml.Dom.XmlDocument object containing
            // the toast XML
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);

            // You can use the methods from the XML document to specify all of the
            // required parameters for the toast.
            XmlNodeList stringElements = toastXml.GetElementsByTagName("text");
            stringElements.Item(0).AppendChild(toastXml.CreateTextNode("Push notification message:"));
            stringElements.Item(1).AppendChild(toastXml.CreateTextNode(messageReceived));

            // If comment out the next lines, the toast still makes noise.
            //// Audio tags are not included by default, so must be added to the XML document.
            //string audioSrc = "ms-winsoundevent:Notification.IM";
            //XmlElement audioElement = toastXml.CreateElement("audio");
            //audioElement.SetAttribute("src", audioSrc);

            //IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
            //toastNode.AppendChild(audioElement);

            // Create a toast from the Xml, then create a ToastNotifier object to show the toast.
            var sdfg = toastXml.GetXml();
            ToastNotification toast = new ToastNotification(toastXml);
            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
開發者ID:kiewic,項目名稱:Questions,代碼行數:26,代碼來源:TimerTask.cs

示例3: ShowToastNotification

        /// <summary>
        /// 彈出通知toast,使用方法:ShowToastNotification("Square150x150Logo.scale-200.png", $"已複製 {val}", NotificationAudioNames.Default);
        /// </summary>
        /// <param name="assetsImageFileName">在Asserts根目錄下的圖片名稱,注意必須在Assets文件夾下,具體參見源碼</param>
        /// <param name="text">通知的文本信息</param>
        /// <param name="audioName">通知的聲音,源碼有自定義枚舉</param>
        /// 來源:http://edi.wang/post/2015/11/8/uwp-toast-notification
        public static void ShowToastNotification(string assetsImageFileName, string text, NotificationAudioNames audioName)
        {
            // 1. create element
            ToastTemplateType toastTemplate = ToastTemplateType.ToastImageAndText01;
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

            // 2. provide text
            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
            toastTextElements[0].AppendChild(toastXml.CreateTextNode(text));

            // 3. provide image
            XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image");
            ((XmlElement)toastImageAttributes[0]).SetAttribute("src", $"ms-appx:///Assets/{assetsImageFileName}");
            ((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "logo");

            // 4. duration
            IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
            ((XmlElement)toastNode).SetAttribute("duration", "short");

            // 5. audio
            XmlElement audio = toastXml.CreateElement("audio");
            audio.SetAttribute("src", $"ms-winsoundevent:Notification.{audioName.ToString().Replace("_", ".")}");
            toastNode.AppendChild(audio);

            // 6. app launch parameter
            //((XmlElement)toastNode).SetAttribute("launch", "{\"type\":\"toast\",\"param1\":\"12345\",\"param2\":\"67890\"}");

            // 7. send toast
            ToastNotification toast = new ToastNotification(toastXml);
            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
開發者ID:cnlinxi,項目名稱:WebApiDemo,代碼行數:38,代碼來源:Helper.cs

示例4: ShowCore

        static async Task<bool?> ShowCore(XmlDocument rpDocument)
        {
            var rCompletionSource = new TaskCompletionSource<bool?>();

            var rNotification = new ToastNotification(rpDocument);

            TypedEventHandler<ToastNotification, object> rActivated = (s, e) => rCompletionSource.SetResult(true);
            rNotification.Activated += rActivated;

            TypedEventHandler<ToastNotification, ToastDismissedEventArgs> rDismissed = (s, e) => rCompletionSource.SetResult(false);
            rNotification.Dismissed += rDismissed;

            TypedEventHandler<ToastNotification, ToastFailedEventArgs> rFailed = (s, e) => rCompletionSource.SetResult(null);
            rNotification.Failed += rFailed;

            r_Notifier.Show(rNotification);

            var rResult = await rCompletionSource.Task;

            rNotification.Activated -= rActivated;
            rNotification.Dismissed -= rDismissed;
            rNotification.Failed -= rFailed;

            return rResult;
        }
開發者ID:KodamaSakuno,項目名稱:Sakuno.Toast,代碼行數:25,代碼來源:ToastNotificationUtil.cs

示例5: Hide

        public void Hide()
        {
            if (_toast == null) return;

            ToastNotificationManager.CreateToastNotifier(_applicationId).Hide(_toast);
            _toast = null;
        }
開發者ID:CuteITGuy,項目名稱:CB.Windows.UI,代碼行數:7,代碼來源:Toast.cs

示例6: DisplayLongToast

        void DisplayLongToast(bool loopAudio)
        {
            IToastText02 toastContent = ToastContentFactory.CreateToastText02();

            // Toasts can optionally be set to long duration
            toastContent.Duration = ToastDuration.Long;

            toastContent.TextHeading.Text = "Long Duration Toast";

            if (loopAudio)
            {
                toastContent.Audio.Loop = true;
                toastContent.Audio.Content = ToastAudioContent.LoopingAlarm;
                toastContent.TextBodyWrap.Text = "Looping audio";
            }
            else
            {
                toastContent.Audio.Content = ToastAudioContent.IM;
            }

            scenario6Toast = toastContent.CreateNotification();
            ToastNotificationManager.CreateToastNotifier().Show(scenario6Toast);

            rootPage.NotifyUser(toastContent.GetContent(), NotifyType.StatusMessage);
        }
開發者ID:mbin,項目名稱:Win81App,代碼行數:25,代碼來源:ScenarioInput6.xaml.cs

示例7: GenerateTcs

 static TaskCompletionSource<bool?> GenerateTcs(ToastNotification notification) {
     var tcs = new TaskCompletionSource<bool?>();
     notification.Dismissed += (sender, args) => tcs.SetResult(false);
     notification.Activated += (sender, args) => tcs.SetResult(true);
     notification.Failed += (sender, args) => tcs.SetException(args.ErrorCode);
     return tcs;
 }
開發者ID:SIXNetworks,項目名稱:withSIX.Desktop,代碼行數:7,代碼來源:WinRTNotificationProvider.cs

示例8: Initialize

        private void Initialize()
        {
            // Clear all existing notifications
            ToastNotificationManager.History.Clear();

            var longTime = new Windows.Globalization.DateTimeFormatting.DateTimeFormatter("longtime");
            DateTimeOffset expiryTime = DateTime.Now.AddSeconds(30);
            string expiryTimeString = longTime.Format(expiryTime);

            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
            //Find the text component of the content
            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");

            // Set the text on the toast. 
            // The first line of text in the ToastText02 template is treated as header text, and will be bold.
            toastTextElements[0].AppendChild(toastXml.CreateTextNode("Expiring Toast"));
            toastTextElements[1].AppendChild(toastXml.CreateTextNode("It will expire at " +  expiryTimeString));

            // Set the duration on the toast
            IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
            ((XmlElement)toastNode).SetAttribute("duration", "long");

            // Create the actual toast object using this toast specification.
            ToastNotification toast = new ToastNotification(toastXml);

            toast.ExpirationTime = expiryTime;

            // Send the toast.
            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
開發者ID:RasmusTG,項目名稱:Windows-universal-samples,代碼行數:30,代碼來源:ScenarioElement.xaml.cs

示例9: DisplayToast

        private void DisplayToast(IBackgroundTaskInstance taskInstance)
        {
            try
            {
                SmsReceivedEventDetails smsDetails = (SmsReceivedEventDetails)taskInstance.TriggerDetails;

                SmsBinaryMessage smsEncodedmsg = smsDetails.BinaryMessage;

                SmsTextMessage smsTextMessage = Windows.Devices.Sms.SmsTextMessage.FromBinaryMessage(smsEncodedmsg);

                XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);

                XmlNodeList stringElements = toastXml.GetElementsByTagName("text");

                stringElements.Item(0).AppendChild(toastXml.CreateTextNode(smsTextMessage.From));

                stringElements.Item(1).AppendChild(toastXml.CreateTextNode(smsTextMessage.Body));

                ToastNotification notification = new ToastNotification(toastXml);
                ToastNotificationManager.CreateToastNotifier().Show(notification);
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error displaying toast: " + ex.Message);
            }
        }
開發者ID:oldnewthing,項目名稱:old-Windows8-samples,代碼行數:26,代碼來源:SampleSmsBackgroundTask.cs

示例10: Notify

 public static void Notify(int usagePerc, string quotaName)
 {
     var xmlDoc = CreateToast(usagePerc, quotaName);
     var notifier = ToastNotificationManager.CreateToastNotifier();
     var toast = new ToastNotification(xmlDoc);
     notifier.Show(toast);
 }
開發者ID:davidvidmar,項目名稱:MobilnaPoraba,代碼行數:7,代碼來源:Notifications.cs

示例11: UpdateTile

        public static void UpdateTile(int value)
        {
            var type = BadgeTemplateType.BadgeNumber;
            var xml = BadgeUpdateManager.GetTemplateContent(type);
            var elements = xml.GetElementsByTagName("badge");
            var element = elements[0] as XmlElement;
            element.SetAttribute("value", value.ToString());

            var updater = BadgeUpdateManager.CreateBadgeUpdaterForApplication();
            var notification = new BadgeNotification(xml);
            updater.Update(notification);

            Debug.WriteLine("Background task badge updated: " + value.ToString());

            var template = ToastTemplateType.ToastText01;
            xml = ToastNotificationManager.GetTemplateContent(template);
            var text = xml.CreateTextNode(string.Format("Badge updated to {0}", value));
            elements = xml.GetElementsByTagName("text");
            elements[0].AppendChild(text);

            var toast = new ToastNotification(xml);
            var notifier = ToastNotificationManager.CreateToastNotifier();
            notifier.Show(toast);

            Debug.WriteLine("Background task toast shown: " + value.ToString());
        }
開發者ID:MuffPotter,項目名稱:201505-MVA,代碼行數:26,代碼來源:MyUpdateBadgeTask.cs

示例12: CreateTextOnlyToast

        // Note: All toast templates available in the Toast Template Catalog (http://msdn.microsoft.com/en-us/library/windows/apps/hh761494.aspx)
        // are treated as a ToastText02 template on Windows Phone.
        // That template defines a maximum of 2 text elements. The first text element is treated as header text and is always bold.
        // Images will never be downloaded when any of the other templates containing image elements are used, because Windows Phone will
        // not display the image. The app icon (Square 150 x 150) is displayed to the left of the toast text and is also show in the action center.
        public static ToastNotification CreateTextOnlyToast(string toastHeading, string toastBody)
        {
            // Using the ToastText02 toast template.
            ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;

            // Retrieve the content part of the toast so we can change the text.
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

            //Find the text component of the content
            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");

            // Set the text on the toast. 
            // The first line of text in the ToastText02 template is treated as header text, and will be bold.
            toastTextElements[0].AppendChild(toastXml.CreateTextNode(toastHeading));
            toastTextElements[1].AppendChild(toastXml.CreateTextNode(toastBody));

            // Set the duration on the toast
            IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
            ((XmlElement)toastNode).SetAttribute("duration", "long");

            // Create the actual toast object using this toast specification.
            ToastNotification toast = new ToastNotification(toastXml); 

            return toast;
        }
開發者ID:trilok567,項目名稱:Windows-Phone,代碼行數:30,代碼來源:MySampleHelper.cs

示例13: ShowToast

        private void ShowToast()
        {
            // GetTemplateContent returns a Windows.Data.Xml.Dom.XmlDocument object containing
            // the toast XML

            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText04);
            XmlElement xe = toastXml.CreateElement("title");

            // You can use the methods from the XML document to specify all of the
            // required parameters for the toast
            XmlNodeList stringElements = toastXml.GetElementsByTagName("text");

            for (uint i = 0; i < stringElements.Length; i++)
            {
                stringElements.Item(i).AppendChild(toastXml.CreateTextNode("測試 !"));
            }

            // Create a toast from the Xml, then create a ToastNotifier object to show
            // the toast
            ToastNotification toast = new ToastNotification(toastXml);

            // If you have other applications in your package, you can specify the AppId of
            // the app to create a ToastNotifier for that application

            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
開發者ID:zdybit,項目名稱:RememberIt,代碼行數:26,代碼來源:ReviewRemindTask.cs

示例14: SendToast

        private static void SendToast()
        {
            //prepare collection
            List<HolidayItem> collection = _manager.GetHolidayList(DateTime.Now);
            collection = collection.Where(p => p.Day == SelectedDate.Day || p.HolidayName == "google calendar").ToList();

            if (collection.Count > 0)
            {
                foreach (var item in collection)
                {
                    // Using the ToastText02 toast template.
                    ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;

                    // Retrieve the content part of the toast so we can change the text.
                    XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);

                    //Find the text component of the content
                    XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");

                    // Set the text on the toast. 
                    // The first line of text in the ToastText02 template is treated as header text, and will be bold.
                    toastTextElements[0].AppendChild(toastXml.CreateTextNode(SelectedDate.ToString("d")));
                    toastTextElements[1].AppendChild(toastXml.CreateTextNode(item.HolidayName));

                    // Set the duration on the toast
                    IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
                    ((XmlElement)toastNode).SetAttribute("duration", "long");

                    // Create the actual toast object using this toast specification.
                    ToastNotification toast = new ToastNotification(toastXml);
                    ToastNotificationManager.CreateToastNotifier().Show(toast);
                }
            }
        }
開發者ID:Syanne,項目名稱:Holiday-Calendar,代碼行數:34,代碼來源:ToastBackgroundTask.cs

示例15: btnLocatToastWithAction_Click

        private void btnLocatToastWithAction_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            string title = "Você recebeu uma imagem";
            string content = "Check this out, Happy Canyon in Utah!";
            string image = "http://blogs.msdn.com/cfs-filesystemfile.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-71-81-permanent/2727.happycanyon1_5B00_1_5D00_.jpg";

            string toastActions =
            [email protected]"<toast>
                <visual>
                    <binding template='ToastGeneric'>
                        <text>{title}</text>
                        <text>{content}</text>
                        <image src='{image}' placement='appLogoOverride' hint-crop='circle'/>
                    </binding>
                </visual>
                <actions>
                    <input id = 'message' type = 'text' placeholderContent = 'reply here' />
                    <action activationType = 'background' content = 'reply' arguments = 'reply' />
                    <action activationType = 'foreground' content = 'video call' arguments = 'video' />
                </actions>
            </toast>";

            XmlDocument x = new XmlDocument();
            x.LoadXml(toastActions);
            ToastNotification t = new ToastNotification(x);
            ToastNotificationManager.CreateToastNotifier().Show(t);
        }
開發者ID:rogeriohc,項目名稱:NavPaneApp1,代碼行數:27,代碼來源:Page3.xaml.cs


注:本文中的Windows.UI.Notifications.ToastNotification類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。