[源码下载]

背水一战 Windows 10 (104) - 通知(Toast): 纯文本 toast, 短时 toast, 长时 toast, 图文 toast

作者:webabcd

介绍
背水一战 Windows 10 之 通知(Toast)

  • 纯文本 toast
  • 短时 toast
  • 长时 toast
  • 图文 toast

示例
1、本例用于演示如何弹出纯文本 toast,以及如何控制 toast 的显示时长(短时和长时两种)
Notification/Toast/Text.xaml

<Page
x:Class="Windows10.Notification.Toast.Text"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Notification.Toast"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="10 0 10 10"> <Button Name="buttonShowToast1" Content="显示 toast(短时通知)" Click="buttonShowToast1_Click" Margin="5" /> <Button Name="buttonShowToast2" Content="显示 toast(长时通知)" Click="buttonShowToast2_Click" Margin="5" /> </StackPanel>
</Grid>
</Page>

Notification/Toast/Text.xaml.cs

/*
* 本例用于演示如何弹出纯文本 toast,以及如何控制 toast 的显示时长(短时和长时两种)
* 单击 toast 激活 app 后(前台方式激活),如何获取相关信息请参见 Demo.xaml.cs 中的代码
*
*
* 本例 xml 说明:
* activationType - 通过点击 toast 激活 app 时的激活方式,foreground 代表前台方式激活
* launch - 通过点击 toast 激活 app 时,传递给 app 的参数(通过按钮激活时,此参数无效)
* duration - short 短时通知(默认值);long 长时通知
* template - 在 uwp 中就 ToastGeneric 一种模板
* text - 每一个新的 text 会另起一行,一行显示不下会自动换行,第一个 text 会高亮显示,最多显示 5 行文本
*/ using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; namespace Windows10.Notification.Toast
{
public sealed partial class Text : Page
{
public Text()
{
this.InitializeComponent();
} // 弹出 toast 通知(短时通知)
private void buttonShowToast1_Click(object sender, RoutedEventArgs e)
{
// 清除本 app 的之前的全部 toast 通知
// ToastNotificationManager.History.Clear(); string toastXml = @"
<toast activationType='foreground' launch='Notification-Toast-Text-Arguments 1'>
<visual>
<binding template='ToastGeneric'>
<text>toast - title</text>
<text>toast - content</text>
<text>""Hololens""引领技术革命浪潮传统的人机交互,主要是通过键盘和触摸,包括并不能被精确识别的语音等。""Hololens""的出现,则给新一代体验更好的人机交互指明道路,并现实了设备的小型化和便携化。</text>
</binding>
</visual>
</toast>"; XmlDocument toastDoc = new XmlDocument();
toastDoc.LoadXml(toastXml); ToastNotification toast = new ToastNotification(toastDoc);
ToastNotificationManager.CreateToastNotifier().Show(toast);
} // 弹出 toast 通知(长时通知)
private void buttonShowToast2_Click(object sender, RoutedEventArgs e)
{
// 清除本 app 的之前的全部 toast 通知
// ToastNotificationManager.History.Clear(); string toastXml = @"
<toast activationType='foreground' duration='long' launch='Notification-Toast-Text-Arguments 2'>
<visual>
<binding template='ToastGeneric'>
<text>toast - title</text>
<text>""Hololens""引领技术革命浪潮传统的人机交互,主要是通过键盘和触摸,包括并不能被精确识别的语音等。""Hololens""的出现,则给新一代体验更好的人机交互指明道路,并现实了设备的小型化和便携化。</text>
</binding>
</visual>
</toast>"; XmlDocument toastDoc = new XmlDocument();
toastDoc.LoadXml(toastXml); ToastNotification toast = new ToastNotification(toastDoc);
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
}
}

2、本例用于演示如何弹出图文 toast
Notification/Toast/TextAndImage.xaml

<Page
x:Class="Windows10.Notification.Toast.TextAndImage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Notification.Toast"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"> <Grid Background="Transparent">
<StackPanel Margin="10 0 10 10"> <Button Name="buttonShowToastImageFromAppPackage" Content="显示 toast(图片来自 AppPackage)" Click="buttonShowToastImageFromAppPackage_Click" Margin="5" /> <Button Name="buttonShowToastImageFromAppData" Content="弹出 toast 通知(图片来自 AppData,image 的 hint-crop 为 circle)" Click="buttonShowToastImageFromAppData_Click" Margin="5" /> <Button Name="buttonShowToastImageFromHttp" Content="弹出 toast 通知(图片来自 http,image 的 placement 为 appLogoOverride,image 的 addImageQuery 为 true)" Click="buttonShowToastImageFromHttp_Click" Margin="5" /> </StackPanel>
</Grid>
</Page>

Notification/Toast/TextAndImage.xaml.cs

/*
* 本例用于演示如何弹出图文 toast
* 单击 toast 激活 app 后(前台方式激活),如何获取相关信息请参见 Demo.xaml.cs 中的代码
*
*
* 本例 xml 说明:
* activationType - 通过点击 toast 激活 app 时的激活方式,foreground 代表前台方式激活
* launch - 通过点击 toast 激活 app 时,传递给 app 的参数(通过按钮激活时,此参数无效)
* template - 在 uwp 中就 ToastGeneric 一种模板
* text - 每一个新的 text 会另起一行,一行显示不下会自动换行,第一个 text 会高亮显示,最多显示 5 行文本
* image - 图片,最多显示一张图片
* hint-crop
* none - 图片不剪裁(默认值)
* circle - 图片剪裁成圆形
* placement
* inline - 图片显示在 toast 的文本的下面(默认值)
* appLogoOverride - 图片显示在 toast 的左上角
* addImageQuery
* 是否将当前的部分环境信息以 url 参数的方式附加到图片地址中(一个 bool 值,默认值为 false)
* 除了在 image 节点设置外,也可以在 visual 节点或 binding 节点设置
*
*
* 注:图片不能大于 1024x1024 像素,不能大于 200 KB,类型必须为 .png .jpg .jpeg .gif
*/ using System;
using Windows.Data.Xml.Dom;
using Windows.Storage;
using Windows.UI.Notifications;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; namespace Windows10.Notification.Toast
{
public sealed partial class TextAndImage : Page
{
public TextAndImage()
{
this.InitializeComponent();
} // 弹出 toast 通知(图片来自 AppPackage)
private void buttonShowToastImageFromAppPackage_Click(object sender, RoutedEventArgs e)
{
// 清除本 app 的之前的全部 toast 通知
// ToastNotificationManager.History.Clear(); string toastXml = @"
<toast activationType='foreground' launch='Notification-Toast-TextAndImage-Arguments 1'>
<visual>
<binding template='ToastGeneric'>
<text>toast - title</text>
<text>""Hololens""引领技术革命浪潮传统的人机交互,主要是通过键盘和触摸,包括并不能被精确识别的语音等。""Hololens""的出现,则给新一代体验更好的人机交互指明道路,并现实了设备的小型化和便携化。</text>
<image src='ms-appx:///Assets/hololens.jpg' />
</binding>
</visual>
</toast>"; XmlDocument toastDoc = new XmlDocument();
toastDoc.LoadXml(toastXml); ToastNotification toast = new ToastNotification(toastDoc);
ToastNotificationManager.CreateToastNotifier().Show(toast);
} // 弹出 toast 通知(图片来自 AppData,image 的 hint-crop 为 circle)
private async void buttonShowToastImageFromAppData_Click(object sender, RoutedEventArgs e)
{
// 清除本 app 的之前的全部 toast 通知
// ToastNotificationManager.History.Clear(); StorageFolder localFolder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("webabcdTest", CreationCollisionOption.OpenIfExists);
StorageFile packageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/hololens.jpg"));
await packageFile.CopyAsync(localFolder, "hololens.jpg", NameCollisionOption.ReplaceExisting); string toastXml = @"
<toast activationType='foreground' launch='Notification-Toast-TextAndImage-Arguments 2'>
<visual>
<binding template='ToastGeneric'>
<text>toast - title</text>
<text>""Hololens""引领技术革命浪潮传统的人机交互,主要是通过键盘和触摸,包括并不能被精确识别的语音等。""Hololens""的出现,则给新一代体验更好的人机交互指明道路,并现实了设备的小型化和便携化。</text>
<image src='ms-appdata:///local/webabcdTest/hololens.jpg' hint-crop='circle' />
</binding>
</visual>
</toast>"; XmlDocument toastDoc = new XmlDocument();
toastDoc.LoadXml(toastXml); ToastNotification toast = new ToastNotification(toastDoc);
ToastNotificationManager.CreateToastNotifier().Show(toast);
} // 弹出 toast 通知(图片来自 http,image 的 placement 为 appLogoOverride,image 的 addImageQuery 为 true)
private void buttonShowToastImageFromHttp_Click(object sender, RoutedEventArgs e)
{
// 清除本 app 的之前的全部 toast 通知
// ToastNotificationManager.History.Clear(); /*
* 本例中的 addImageQuery 被指定为 true
* 所以以本例来说图片的实际请求地址为 http://images.cnblogs.com/mvpteam.gif?ms-scale=100&ms-contrast=standard
* 如果不指定 addImageQuery 或者将其设置为 false 则本例的图片的实际请求地址与 src 设置的一致,就是 http://images.cnblogs.com/mvpteam.gif
*/ string toastXml = @"
<toast activationType='foreground' launch='Notification-Toast-TextAndImage-Arguments 3'>
<visual addImageQuery='true'>
<binding template='ToastGeneric'>
<text>toast - title</text>
<text>""Hololens""引领技术革命浪潮传统的人机交互,主要是通过键盘和触摸,包括并不能被精确识别的语音等。""Hololens""的出现,则给新一代体验更好的人机交互指明道路,并现实了设备的小型化和便携化。</text>
<image src='http://images.cnblogs.com/mvpteam.gif3' placement='appLogoOverride' />
</binding>
</visual>
</toast>"; XmlDocument toastDoc = new XmlDocument();
toastDoc.LoadXml(toastXml); ToastNotification toast = new ToastNotification(toastDoc);
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
}
}

OK
[源码下载]

背水一战 Windows 10 (104) - 通知(Toast): 纯文本 toast, 短时 toast, 长时 toast, 图文 toast的更多相关文章

  1. 背水一战 Windows 10 (105) - 通知(Toast): 带按钮的 toast, 带输入的 toast(文本输入框,下拉选择框)

    [源码下载] 背水一战 Windows 10 (105) - 通知(Toast): 带按钮的 toast, 带输入的 toast(文本输入框,下拉选择框) 作者:webabcd 介绍背水一战 Wind ...

  2. 背水一战 Windows 10 (106) - 通知(Toast): 通过 toast 打开协议, 通过 toast 选择在指定的时间之后延迟提醒或者取消延迟提醒

    [源码下载] 背水一战 Windows 10 (106) - 通知(Toast): 通过 toast 打开协议, 通过 toast 选择在指定的时间之后延迟提醒或者取消延迟提醒 作者:webabcd ...

  3. 背水一战 Windows 10 (110) - 通知(Tile): secondary tile 模板之基础, secondary tile 模板之文本

    [源码下载] 背水一战 Windows 10 (110) - 通知(Tile): secondary tile 模板之基础, secondary tile 模板之文本 作者:webabcd 介绍背水一 ...

  4. 背水一战 Windows 10 (107) - 通知(Toast): 提示音, 特定场景

    [源码下载] 背水一战 Windows 10 (107) - 通知(Toast): 提示音, 特定场景 作者:webabcd 介绍背水一战 Windows 10 之 通知(Toast) 提示音 特定场 ...

  5. 背水一战 Windows 10 (103) - 通知(Toast): 基础, 按计划显示 toast 通知

    [源码下载] 背水一战 Windows 10 (103) - 通知(Toast): 基础, 按计划显示 toast 通知 作者:webabcd 介绍背水一战 Windows 10 之 通知(Toast ...

  6. 背水一战 Windows 10 (30) - 控件(文本类): AutoSuggestBox

    [源码下载] 背水一战 Windows 10 (30) - 控件(文本类): AutoSuggestBox 作者:webabcd 介绍背水一战 Windows 10 之 控件(文本类) AutoSug ...

  7. 背水一战 Windows 10 (28) - 控件(文本类): TextBox, PasswordBox

    [源码下载] 背水一战 Windows 10 (28) - 控件(文本类): TextBox, PasswordBox 作者:webabcd 介绍背水一战 Windows 10 之 控件(文本类) T ...

  8. 背水一战 Windows 10 (111) - 通知(Tile): secondary tile 模板之图片, secondary tile 模板之分组

    [源码下载] 背水一战 Windows 10 (111) - 通知(Tile): secondary tile 模板之图片, secondary tile 模板之分组 作者:webabcd 介绍背水一 ...

  9. 背水一战 Windows 10 (29) - 控件(文本类): RichTextBlock, RichTextBlockOverflow, RichEditBox

    [源码下载] 背水一战 Windows 10 (29) - 控件(文本类): RichTextBlock, RichTextBlockOverflow, RichEditBox 作者:webabcd ...

随机推荐

  1. python_字符编码

    一 了解字符编码的知识储备 1.计算机基础知识 2.电脑存放组成: 硬盘 - 内存 -(二级缓存.一级缓存.cpu寄存器)- cpu # cpu交互的是用户能识别的数据:字符# 硬盘中最终存储的数据: ...

  2. 《剑指Offer》第20题(Java实现):定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为O(1))。

    一.题目描述 定义栈的数据结构,请在该类型中实现一个能够得到栈中所含最小元素的min函数(时间复杂度应为O(1)). 二.思路解析 首先定义一个Integer类型的栈,记为stack,此栈用来完成数据 ...

  3. C#导入c++ dll报找不到dll文件 masm32调用c++类库

    最近需要在C#下调用一个c++ dll库,不管怎样dllimport就是报错找不到该dll文件,路径.函数名称.参数.dllimport参数逐个检查确认无误也无济于事,无奈想用其他语言调用试试,由于是 ...

  4. 安装mitmproxy

    https://www.jianshu.com/p/1dd40826113b 先连接到同一个局域网,再访问官网下载描述文件

  5. CSS3扫描动画效果

    .swiper-animate { position: absolute; width: 100%; height: 100%; left:; top:; z-index:; background: ...

  6. linux awk使用详解

    转载:https://www.cnblogs.com/xudong-bupt/p/3721210.html   awk是行处理器: 相比较屏幕处理的优点,在处理庞大文件时不会出现内存溢出或是处理缓慢的 ...

  7. 跨域的处理方式 JSONP和CORS和反向代理

    什么是跨域? 首先了解同源策略,三个相同,协议,域名端口号相同就是同源,那么三者有任意不同就会造成跨域.跨域不常见,跨域基本上就是访问别人的资源. 如何解决跨域问题? 常见的有三种 一:jsonp处理 ...

  8. sqlserver 并行度

    转载地址:http://www.cnblogs.com/zhijianliutang/p/4148540.html

  9. 使用C#重写网上的60行 Javascript 俄罗斯方块源码 (带注释)

    在很久很久以前,就已经看过 60行Js的俄罗斯方块源码.无奈当时能力不够看明白,当时觉得就是个神作. 现在总算有空再看了,顺便用c#实现一遍(超过60行),顺道熟悉下Js API. 网上其他博客也有分 ...

  10. DNN原理探究系列之目录与序章篇

    序言: 神经网络结构,作为最成功的机器学习模型之一,其工作原理一直被埋藏得比较深,其解释性以至于被称为黑盒. 自己对于DNN的理解也只能算刚踏入了门槛,对于人脑的原理与DNN原理之间的互通性,一直是非 ...