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);
            }

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

  • 相关阅读:
    eclipse使用egit提交代码报错
    JMeter使用代理录制脚本
    Jenkins搭建Windows slave 环境
    nmon在线安装及使用
    netstat 查看连接数
    Node.js安装及环境配置之Windows篇(转:https://www.cnblogs.com/zhouyu2017/p/6485265.html)
    HTTP状态码图示
    高并发带来的重复提交问题解决方案
    redis 主从备份自动切换+java代码实现类
    转:Redis 缓存策略
  • 原文地址:https://www.cnblogs.com/shi-meng/p/4076612.html
Copyright © 2011-2022 走看看