Toast 通知(Windows 应用商店应用)

8 篇文章 0 订阅
    MSDN 有关 toast  文档: http://msdn.microsoft.com/zh-cn/library/windows/apps/hh779727.aspx

                                    模版 : http://msdn.microsoft.com/zh-cn/library/windows/apps/hh761494.aspx

win8 的 toast 通知和 wp 的类似。win 8 的 toast 是显示在屏幕右上角,可以有文字,也可以加上图片。系统的通知同时做多显示三个,

如果多余三个,就会把多余的通知放到系统队列中,然后各个 Toast 通知依次显示固定时间。

在 Windows.UI.Notifications 命名空间下的枚举:

    // 摘要:
    //     指定要在消息通知中使用的模版。   
    public enum ToastTemplateType
    {
        // 摘要:
        //     在三行文本中被包装的大型图像和单个字符串。
        ToastImageAndText01 = 0,
        //
        // 摘要:
        //     大图像、加粗文本的一个字符串在第一行、常规文本的一个字符串包装在第二、三行中。
        ToastImageAndText02 = 1,
        //
        // 摘要:
        //     大图像、加粗文本的一个字符串被包装在开头两行中、常规文本的一个字符串包装在第三行中。
        ToastImageAndText03 = 2,
        //
        // 摘要:
        //     大图像、加粗文本的一个字符串在第一行、常规文本的一个字符串在第二行中、常规文本的一个字符串在第三行中。
        ToastImageAndText04 = 3,
        //
        // 摘要:
        //     包装在三行文本中的单个字符串。
        ToastText01 = 4,
        //
        // 摘要:
        //     第一行中加粗文本的一个字符串、覆盖第二行和第三行的常规文本的一个字符串。
        ToastText02 = 5,
        //
        // 摘要:
        //     覆盖第一行和第二行的加粗文本的一个字符串。第三行中常规文本的一个字符串。
        ToastText03 = 6,
        //
        // 摘要:
        //     第一行中加粗文本的一个字符串、第二行中常规文本的一个字符串、第三行中常规文本的一个字符串。
        ToastText04 = 7,
    }
调用页面中的另一个方法:
void DisplayTextToastWithStringManipulation(ToastTemplateType templateType)
        {
            string toastXmlString = String.Empty;
            if (templateType == ToastTemplateType.ToastText01)
            {
                toastXmlString = "<toast>"
                               + "<visual version='1'>"
                               + "<binding template='ToastText01'>"
                               + "<text id='1'>Body text that wraps over three lines</text>"
                               + "</binding>"
                               + "</visual>"
                               + "</toast>";
            }
            else if (templateType == ToastTemplateType.ToastText02)
            {
                toastXmlString = "<toast>"
                               + "<visual version='1'>"
                               + "<binding template='ToastText02'>"
                               + "<text id='1'>Heading text</text>"
                               + "<text id='2'>Body text that wraps over two lines</text>"
                               + "</binding>"
                               + "</visual>"
                               + "</toast>";
            }
            else if (templateType == ToastTemplateType.ToastText03)
            {
                toastXmlString = "<toast>"
                               + "<visual version='1'>"
                               + "<binding template='ToastText03'>"
                               + "<text id='1'>Heading text that is very long and wraps over two lines</text>"
                               + "<text id='2'>Body text</text>"
                               + "</binding>"
                               + "</visual>"
                               + "</toast>";
            }
            else if (templateType == ToastTemplateType.ToastText04)
            {
                toastXmlString = "<toast>"
                               + "<visual version='1'>"
                               + "<binding template='ToastText04'>"
                               + "<text id='1'>Heading text</text>"
                               + "<text id='2'>First body text</text>"
                               + "<text id='3'>Second body text</text>"
                               + "</binding>"
                               + "</visual>"
                               + "</toast>";
            }

            Windows.Data.Xml.Dom.XmlDocument toastDOM = new Windows.Data.Xml.Dom.XmlDocument();
            toastDOM.LoadXml(toastXmlString);
         
           
            ToastNotification toast = new ToastNotification(toastDOM);

            ToastNotificationManager.CreateToastNotifier().Show(toast);
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值