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

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

  • 相关阅读:
    【题解】[Codeforces 1221D] Make The Fence Great Again【DP】
    PAM / 回文自动机(回文树)略解
    【AGC048F】【2020六校联考WC #9】序列【构造】【DP】
    json解析:[2]fastjson 使用
    JAVA获取时间戳,哪个更快
    Android拍照、录像、录音代码范例
    取消GridView/ListView item被点击时的效果
    Android中使用speex将PCM录音格式转Wav格式
    【Android】【录音】Android录音--AudioRecord、MediaRecorder
    Android软键盘遮挡的四种解决方案
  • 原文地址:https://www.cnblogs.com/shi-meng/p/4076612.html
Copyright © 2011-2022 走看看