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


C# ToastNotification.GetType方法代碼示例

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


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

示例1: CreateToastNotification

 public static void CreateToastNotification(ForumThreadEntity forumThread)
 {
     string replyText = forumThread.RepliesSinceLastOpened > 1 ? " has {0} replies." : " has {0} reply.";
     XmlDocument notificationXml =
         ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastImageAndText02);
     XmlNodeList toastElements = notificationXml.GetElementsByTagName("text");
     toastElements[0].AppendChild(
         notificationXml.CreateTextNode(string.Format("\"{0}\"", forumThread.Name)));
     toastElements[1].AppendChild(
         notificationXml.CreateTextNode(string.Format(replyText, forumThread.RepliesSinceLastOpened)));
     XmlNodeList imageElement = notificationXml.GetElementsByTagName("image");
     string imageName = string.Empty;
     if (string.IsNullOrEmpty(imageName))
     {
         imageName = forumThread.ImageIconLocation;
     }
     imageElement[0].Attributes[1].NodeValue = imageName;
     IXmlNode toastNode = notificationXml.SelectSingleNode("/toast");
     string test = "{" + string.Format("type:'toast', 'threadId':{0}", forumThread.ThreadId) + "}";
     var xmlElement = (XmlElement)toastNode;
     if (xmlElement != null) xmlElement.SetAttribute("launch", test);
     var toastNotification = new ToastNotification(notificationXml);
     var nameProperty = toastNotification.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "Tag");
     if (nameProperty != null)
     {
         nameProperty.SetValue(toastNotification, forumThread.ThreadId.ToString());
     }
     ToastNotificationManager.CreateToastNotifier().Show(toastNotification);
 }
開發者ID:jessicahuynh,項目名稱:Awful-Forums-Reader,代碼行數:29,代碼來源:NotifyStatusTile.cs

示例2: Basic

        public static void Basic(string msg, bool playJingle = false, string toastId = "")
        {
            ToastTemplateType toastTemplate = ToastTemplateType.ToastText01;
            XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
            XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
            toastTextElements[0].AppendChild(toastXml.CreateTextNode(msg));
            if (!playJingle)
            {
                IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); 
                XmlElement audio = toastXml.CreateElement("audio"); 
                audio.SetAttribute("silent", "true");
                toastNode?.AppendChild(audio);
            }

            ToastNotification toast = new ToastNotification(toastXml);
            var nameProperty = toast.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "Tag");
            if (nameProperty != null && !string.IsNullOrEmpty(toastId))
            {
               nameProperty.SetValue(toast, toastId);
            }
            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }
開發者ID:robUx4,項目名稱:vlc-winrt,代碼行數:22,代碼來源:ToastHelper.cs

示例3: Run

        // The Run method is the entry point of a background task.
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            Debug.WriteLine("Background " + taskInstance.Task.Name + " starting...");

            // Associate a cancelation handler with the background task for handlers
            // that may take a considerable time to complete.
            taskInstance.Canceled += new BackgroundTaskCanceledEventHandler(OnCanceled);

            // Do the background task activity. First, get the authentication context.
            Debug.WriteLine("Getting event details");
            var details = taskInstance.TriggerDetails as HotspotAuthenticationEventDetails;

            HotspotAuthenticationContext context;
            if (!HotspotAuthenticationContext.TryGetAuthenticationContext(details.EventToken, out context))
            {
                // The event is not targetting this application. There is no further processing to do.
                Debug.WriteLine("Failed to get event context");
                return;
            }

            byte[] ssid = context.WirelessNetworkId;
            Debug.WriteLine("SSID: " + System.Text.UTF8Encoding.UTF8.GetString(ssid, 0, ssid.Length));

            // Get configuration from application storage.
            bool markAsManualConnect = ConfigStore.MarkAsManualConnect;

            if (ConfigStore.UseNativeWISPr)
            {
                // Following code can be used if using native WISPr implementation. Please note that 
                // following HotspotAuthenticationContext properties only work on windows and not on windows phone. 
                // On Windows Phone they return un-useful strings
                // Developers are expected to implement their own WISPr implementation on Phone
             
                Debug.WriteLine("AuthenticationUrl: " + context.AuthenticationUrl.OriginalString);
                Debug.WriteLine("RedirectMessageUrl: " + context.RedirectMessageUrl.OriginalString);
                Debug.WriteLine("RedirectMessageXml: " + context.RedirectMessageXml.GetXml());

                // In this sample, the AuthenticationUrl is always checked in the background task handler
                // to avoid launching the foreground app in case the authentication host is not trusted.
                if (ConfigStore.AuthenticationHost != context.AuthenticationUrl.Host)
                {
                    // Hotspot is not using the trusted authentication server.
                    // Abort authentication and disconnect.
                    Debug.WriteLine("Authentication server is untrusted");
                    context.AbortAuthentication(markAsManualConnect);
                    return;
                }
            }

            // Check if authentication is handled by foreground app.
            if (!ConfigStore.AuthenticateThroughBackgroundTask)
            {
                Debug.WriteLine("Triggering foreground application");
                // Pass event token to application
                ConfigStore.AuthenticationToken = details.EventToken;


                // Trigger notification  
                // Since TriggerAttentionRequired function throws NotImplementedException on phone we will be using
                // regular Toast Notification to notify user about the authentication, Tapping on the notification will
                // launch the application where user can complete the authentication
                if (ConfigStore.UseNativeWISPr)
                {
                    context.TriggerAttentionRequired(_foregroundAppId, "");
                }
                else
                {
                    var toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
                    toastXml.GetElementsByTagName("text")[0].AppendChild(toastXml.CreateTextNode("Auth by foreground"));
                    IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
                    ((XmlElement)toastNode).SetAttribute("launch", "AuthByForeground");

                    dynamic toast = new ToastNotification(toastXml);
                    Type typeofToastNotification = toast.GetType();
                    PropertyInfo tagProperty = typeofToastNotification.GetRuntimeProperty("Tag");
                    PropertyInfo groupProperty = typeofToastNotification.GetRuntimeProperty("Group");
                    if (tagProperty != null) toast.Tag = "AuthByForeground";
                    if (groupProperty != null) toast.Group = "HotspotAuthAPI";

                    var notification = ToastNotificationManager.CreateToastNotifier();
                    notification.Show(toast);
                }
                                  
                return;
            }

            // Handle authentication in background task.

            // In case this handler performs more complex tasks, it may get canceled at runtime.
            // Check if task was canceled by now.
            if (_cancelRequested)
            {
                // In case the task handler takes too long to generate credentials and gets canceled,
                // the handler should terminate the authentication by aborting it
                Debug.WriteLine("Aborting authentication");
                context.AbortAuthentication(markAsManualConnect);
                return;
            }

//.........這裏部分代碼省略.........
開發者ID:badreddine-dlaila,項目名稱:Windows-8.1-Universal-App,代碼行數:101,代碼來源:BackgroundTask.cs

示例4: CreateToastNotification

        public static void CreateToastNotification(ForumThreadEntity forumThread)
        {
            string replyText = forumThread.RepliesSinceLastOpened > 1 ? " has {0} replies." : " has {0} reply.";
            string test = "{" + string.Format("type:'toast', 'threadId':{0}", forumThread.ThreadId) + "}";
            ToastContent content = new ToastContent()
            {
                Launch = test,
                Visual = new ToastVisual()
                {
                    TitleText = new ToastText()
                    {
                        Text = string.Format("\"{0}\"", forumThread.Name)
                    },
                    BodyTextLine1 = new ToastText()
                    {
                        Text = string.Format(replyText, forumThread.RepliesSinceLastOpened)
                    },
                    AppLogoOverride = new ToastAppLogo()
                    {
                        Source = new ToastImageSource(forumThread.ImageIconLocation)
                    }
                },
                Actions = new ToastActionsCustom()
                {
                    Buttons =
                    {
                        new ToastButton("Open Thread", test)
                        {
                            ActivationType = ToastActivationType.Foreground
                        },
                        new ToastButton("Sleep", "sleep")
                        {
                            ActivationType = ToastActivationType.Background
                        }
                    }
                },
                Audio = new ToastAudio()
                {
                    Src = new Uri("ms-winsoundevent:Notification.Reminder")
                }
            };

            XmlDocument doc = content.GetXml();

            var toastNotification = new ToastNotification(doc);
            var nameProperty = toastNotification.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name == "Tag");
            nameProperty?.SetValue(toastNotification, forumThread.ThreadId.ToString());
            ToastNotificationManager.CreateToastNotifier().Show(toastNotification);
        }
開發者ID:Ephemerial,項目名稱:Awful-Forums-Reader,代碼行數:49,代碼來源:NotifyStatusTile.cs


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