zoukankan      html  css  js  c++  java
  • windows phone 8.1开发笔记之Toast

    Toast(吐司)是wp屏幕上端弹出来的临时通知,他会存在7秒钟的时间,可以快速定位到用户需要的位置(当然是由开发者设置的)

    1.创建一个Toast

       now,需要将你的app设置支持Toast 否则即使你写好了,他也是不工作的 。

      应用程序清单里面直接选择就OK了。

      

      然后看一段代码示例:

      

    public void ToastNotification()
            {
                XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText01);
                XmlNodeList elements = toastXml.GetElementsByTagName("text");
                elements[0].AppendChild(toastXml.CreateTextNode("第一个土司"));
                ToastNotification toast = new ToastNotification(toastXml);
                ToastNotificationManager.CreateToastNotifier().Show(toast);
            }

      在你需要的地方调用:

      

    private void Button_Click(object sender, RoutedEventArgs e)
            {
                ToastNotification();
            }

      Ok,你就可以体验Toast啦!

    2:Toast的过程

      由上不难看出,创建一个头Toast需要4步,1-创建Toast通知模板。2-添加Toast内容。3-创建Toast通知对象。4-弹出通知

    3:定期通知

      有的时间我们需要的是定时通知,程序可以使后台运行运行时,这个时候就要用ScheduledToastNotification了,示例代码:

     private void ToastNotification1()
            {
                //ScheduledToastNotification
                XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
                XmlNodeList toastNodeList = toastXml.GetElementsByTagName("text");
                toastNodeList.Item(0).AppendChild(toastXml.CreateTextNode("Toast Title"));
                toastNodeList.Item(1).AppendChild(toastXml.CreateTextNode("Toast Content"));
                DateTime startTime = DateTime.Now.AddSeconds(20);
                ScheduledToastNotification recurringToast = new ScheduledToastNotification(toastXml, startTime);
                recurringToast.Id = "Scheduled1";
                ToastNotificationManager.CreateToastNotifier().AddToSchedule(recurringToast);
            }

      注意:要加入到构造函数中的哈

  • 相关阅读:
    应用中心无法访问时后台插件列表访问慢的优化
    HTML5 地理定位 【来自百度应用分享平台】
    快捷键补充
    进击的雨燕------------在导航上的UISearchController实现动画效果
    iOS -------- 应用程序引用系统通讯录
    字典和JSON格式字符串相互转换
    进击的雨燕--------------------Swift ? !
    Objective-C多继承的实现
    进击的雨燕------------iOS8中UIAlertController
    进击的雨燕-------------------高级运算符
  • 原文地址:https://www.cnblogs.com/shi-meng/p/4076612.html
Copyright © 2011-2022 走看看