背水一战 Windows 10 (107) - 通知(Toast): 提示音, 特定场景
作者:webabcd
介绍
背水一战 Windows 10 之 通知(Toast)
- 提示音
- 特定场景
示例
1、本例用于演示 toast 的提示音
Notification/Toast/Audio.xaml
<Page
x:Class="Windows10.Notification.Toast.Audio"
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"> <StackPanel Orientation="Horizontal">
<ComboBox x:Name="cmbLoop" Header="loop" Margin="5">
<ComboBoxItem IsSelected="True">false</ComboBoxItem>
<ComboBoxItem>true</ComboBoxItem>
</ComboBox>
<ComboBox x:Name="cmbSilent" Header="silent" Margin="5">
<ComboBoxItem IsSelected="True">false</ComboBoxItem>
<ComboBoxItem>true</ComboBoxItem>
</ComboBox>
<ComboBox x:Name="cmbSrc" Header="src" Margin="5">
<ComboBoxItem IsSelected="True">ms-winsoundevent:Notification.Default</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.IM</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Mail</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Reminder</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.SMS</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Alarm</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Alarm2</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Alarm3</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Alarm4</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Alarm5</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Alarm6</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Alarm7</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Alarm8</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Alarm9</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Alarm10</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Call</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Call2</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Call3</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Call4</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Call5</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Call6</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Call7</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Call8</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Call9</ComboBoxItem>
<ComboBoxItem>ms-winsoundevent:Notification.Looping.Call10</ComboBoxItem>
</ComboBox>
</StackPanel> <Button Name="buttonShowToast1" Content="显示 toast(系统提示音)" Click="buttonShowToast1_Click" Margin="5" /> <Button Name="buttonShowToast2" Content="显示 toast(ms-appx 或 ms-appdata 地址的音频文件)" Click="buttonShowToast2_Click" Margin="5" /> </StackPanel>
</Grid>
</Page>
Notification/Toast/Audio.xaml.cs
/*
* 本例用于演示 toast 的提示音
* 单击 toast 激活 app 后(前台方式激活),如何获取相关信息请参见 Demo.xaml.cs 中的代码
*
*
* 本例 xml 说明:
* audio - 提示音
* src - 播放的提示音的地址。支持系统提示音,ms-appx 地址的音频文件,ms-appdata 地址的音频文件
* loop - 是否循环,默认值为 false
* silent - 是否静音,默认值为 false
*/ 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 Audio : Page
{
public Audio()
{
this.InitializeComponent();
} // 弹出 toast 通知(系统提示音)
private void buttonShowToast1_Click(object sender, RoutedEventArgs e)
{
// 清除本 app 的之前的全部 toast 通知
// ToastNotificationManager.History.Clear(); string toastXml = $@"
<toast activationType='foreground' launch='Notification-Toast-Audio-Arguments 1'>
<visual>
<binding template='ToastGeneric'>
<text>audio</text>
<text>演示 toast 的提示音</text>
</binding>
</visual>
<audio src='{cmbSrc.SelectionBoxItem}' loop='{cmbLoop.SelectionBoxItem}' silent='{cmbSilent.SelectionBoxItem}' />
</toast>"; XmlDocument toastDoc = new XmlDocument();
toastDoc.LoadXml(toastXml); ToastNotification toastNotification = new ToastNotification(toastDoc);
ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();
toastNotifier.Show(toastNotification);
} // 弹出 toast 通知(ms-appx 或 ms-appdata 地址的音频文件)
private void buttonShowToast2_Click(object sender, RoutedEventArgs e)
{
// 清除本 app 的之前的全部 toast 通知
// ToastNotificationManager.History.Clear(); string toastXml = $@"
<toast activationType='foreground' launch='Notification-Toast-Audio-Arguments 1'>
<visual>
<binding template='ToastGeneric'>
<text>audio</text>
<text>演示 toast 的提示音</text>
</binding>
</visual>
<audio src='ms-appx:///Assets/audio.aac' />
</toast>"; XmlDocument toastDoc = new XmlDocument();
toastDoc.LoadXml(toastXml); ToastNotification toastNotification = new ToastNotification(toastDoc);
ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();
toastNotifier.Show(toastNotification);
}
}
}
2、本例用于演示 toast 的不同特定场景
Notification/Toast/Scenario.xaml
<Page
x:Class="Windows10.Notification.Toast.Scenario"
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(reminder 场景)" Click="buttonShowToast2_Click" Margin="5" /> <Button Name="buttonShowToast3" Content="显示 toast(alarm 场景)" Click="buttonShowToast3_Click" Margin="5" /> <Button Name="buttonShowToast4" Content="显示 toast(incomingCall 场景)" Click="buttonShowToast4_Click" Margin="5" /> </StackPanel>
</Grid>
</Page>
Notification/Toast/Scenario.xaml.cs
/*
* 本例用于演示 toast 的不同特定场景
* 单击 toast 激活 app 后(前台方式激活),如何获取相关信息请参见 Demo.xaml.cs 中的代码
*
*
* 本例 xml 说明:
* scenario - 场景类别,不指定则为默认场景
* default - 默认场景
* reminder - 弹出的 toast 框不会消失
* alarm - 弹出的 toast 框不会消失,且使用闹铃提示音
* incomingCall - 弹出的 toast 框不会消失,且按钮样式会与其他场景不同(在 mobile app 中会全屏显示)
*/ 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 Scenario : Page
{
public Scenario()
{
this.InitializeComponent();
} // 弹出 toast 通知(默认场景)
private void buttonShowToast1_Click(object sender, RoutedEventArgs e)
{
// 清除本 app 的之前的全部 toast 通知
// ToastNotificationManager.History.Clear(); string toastXml = @"
<toast activationType='foreground' launch='Notification-Toast-Scenario-Arguments 1'>
<visual>
<binding template='ToastGeneric'>
<text>toast - title</text>
<text>toast - content 1</text>
</binding>
</visual>
</toast>"; XmlDocument toastDoc = new XmlDocument();
toastDoc.LoadXml(toastXml); ToastNotification toastNotification = new ToastNotification(toastDoc);
ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();
toastNotifier.Show(toastNotification);
} // 弹出 toast 通知(reminder 场景)
// 经测试,没有按钮的话则无法实现 reminder 场景的特性
private void buttonShowToast2_Click(object sender, RoutedEventArgs e)
{
// 清除本 app 的之前的全部 toast 通知
// ToastNotificationManager.History.Clear(); string toastXml = @"
<toast activationType='foreground' scenario='reminder' launch='Notification-Toast-Scenario-Arguments 2'>
<visual>
<binding template='ToastGeneric'>
<text>toast - title</text>
<text>toast - content 2</text>
</binding>
</visual>
<actions>
<action content='确认' arguments='confirm' />
</actions>
</toast>"; XmlDocument toastDoc = new XmlDocument();
toastDoc.LoadXml(toastXml); ToastNotification toastNotification = new ToastNotification(toastDoc);
ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();
toastNotifier.Show(toastNotification);
} // 弹出 toast 通知(alarm 场景)
// 经测试,没有按钮的话则无法实现 alarm 场景的特性
private void buttonShowToast3_Click(object sender, RoutedEventArgs e)
{
// 清除本 app 的之前的全部 toast 通知
// ToastNotificationManager.History.Clear(); string toastXml = @"
<toast activationType='foreground' scenario='alarm' launch='Notification-Toast-Scenario-Arguments 3'>
<visual>
<binding template='ToastGeneric'>
<text>toast - title</text>
<text>toast - content 3</text>
</binding>
</visual>
<actions>
<action content='确认' arguments='confirm' />
</actions>
</toast>"; XmlDocument toastDoc = new XmlDocument();
toastDoc.LoadXml(toastXml); ToastNotification toastNotification = new ToastNotification(toastDoc);
ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();
toastNotifier.Show(toastNotification);
} // 弹出 toast 通知(incomingCall 场景)
private void buttonShowToast4_Click(object sender, RoutedEventArgs e)
{
// 清除本 app 的之前的全部 toast 通知
// ToastNotificationManager.History.Clear(); string toastXml = @"
<toast activationType='foreground' scenario='incomingCall' launch='Notification-Toast-Scenario-Arguments 4'>
<visual>
<binding template='ToastGeneric'>
<text>toast - title</text>
<text>toast - content 4</text>
</binding>
</visual>
<actions>
<action content='确认' arguments='confirm' />
</actions>
</toast>"; XmlDocument toastDoc = new XmlDocument();
toastDoc.LoadXml(toastXml); ToastNotification toastNotification = new ToastNotification(toastDoc);
ToastNotifier toastNotifier = ToastNotificationManager.CreateToastNotifier();
toastNotifier.Show(toastNotification);
}
}
}
OK
[源码下载]
背水一战 Windows 10 (107) - 通知(Toast): 提示音, 特定场景的更多相关文章
- 背水一战 Windows 10 (106) - 通知(Toast): 通过 toast 打开协议, 通过 toast 选择在指定的时间之后延迟提醒或者取消延迟提醒
[源码下载] 背水一战 Windows 10 (106) - 通知(Toast): 通过 toast 打开协议, 通过 toast 选择在指定的时间之后延迟提醒或者取消延迟提醒 作者:webabcd ...
- 背水一战 Windows 10 (105) - 通知(Toast): 带按钮的 toast, 带输入的 toast(文本输入框,下拉选择框)
[源码下载] 背水一战 Windows 10 (105) - 通知(Toast): 带按钮的 toast, 带输入的 toast(文本输入框,下拉选择框) 作者:webabcd 介绍背水一战 Wind ...
- 背水一战 Windows 10 (104) - 通知(Toast): 纯文本 toast, 短时 toast, 长时 toast, 图文 toast
[源码下载] 背水一战 Windows 10 (104) - 通知(Toast): 纯文本 toast, 短时 toast, 长时 toast, 图文 toast 作者:webabcd 介绍背水一战 ...
- 背水一战 Windows 10 (103) - 通知(Toast): 基础, 按计划显示 toast 通知
[源码下载] 背水一战 Windows 10 (103) - 通知(Toast): 基础, 按计划显示 toast 通知 作者:webabcd 介绍背水一战 Windows 10 之 通知(Toast ...
- 背水一战 Windows 10 (112) - 通知(Badge): application 的 badge 通知, secondary 的 badge 通知, 轮询服务端以更新 badge 通知
[源码下载] 背水一战 Windows 10 (112) - 通知(Badge): application 的 badge 通知, secondary 的 badge 通知, 轮询服务端以更新 bad ...
- 背水一战 Windows 10 (111) - 通知(Tile): secondary tile 模板之图片, secondary tile 模板之分组
[源码下载] 背水一战 Windows 10 (111) - 通知(Tile): secondary tile 模板之图片, secondary tile 模板之分组 作者:webabcd 介绍背水一 ...
- 背水一战 Windows 10 (110) - 通知(Tile): secondary tile 模板之基础, secondary tile 模板之文本
[源码下载] 背水一战 Windows 10 (110) - 通知(Tile): secondary tile 模板之基础, secondary tile 模板之文本 作者:webabcd 介绍背水一 ...
- 背水一战 Windows 10 (109) - 通知(Tile): 按计划显示 tile 通知, 轮询服务端以更新 tile 通知
[源码下载] 背水一战 Windows 10 (109) - 通知(Tile): 按计划显示 tile 通知, 轮询服务端以更新 tile 通知 作者:webabcd 介绍背水一战 Windows 1 ...
- 背水一战 Windows 10 (108) - 通知(Tile): application tile 基础, secondary tile 基础
[源码下载] 背水一战 Windows 10 (108) - 通知(Tile): application tile 基础, secondary tile 基础 作者:webabcd 介绍背水一战 Wi ...
随机推荐
- SSM商城开发学习
功能模块:前端:门户.商品搜索.商品展示.购物车.注册&登录 后端:商品管理.订单管理.cms 上线,bug,维护,停到上线,维护,打包,上线 某一个模块出现bug,停到这个模块 tomcat ...
- jmeter的各种调用
1. 开发将dubbo协议的接口转化成了webservices后,jmeter直接添加http请求,输入网址就好,但是这种需要增加开发测试页面的工作量 2.jmeter自身无法调用zk连接服务器(Jm ...
- Web自动化附件上传
在进行web界面自动化编写时,可以根据定位元素的方式进行编写,但是如果某一个功能涉及到有附件上传功能,那么该如何解决呢? 继续往下看>>>>> 场景:登录系统后,进行新增 ...
- openstack系列文章(2)dashboard
玩转dashboard之前,考虑一些事情:(1)安全问题:网络访问策略(2)镜像的密码管理:windows或者linux,root或者administrator密码怎么管理(3)怎样创建自己的镜像:w ...
- python基础 (装饰器,内置函数)
https://docs.python.org/zh-cn/3.7/library/functions.html 1.闭包回顾 在学习装饰器之前,可以先复习一下什么是闭包? 在嵌套函数内部的函数可以使 ...
- 新手必备的Linux知识
测试人员为什么学习linux? 对于软件测试人员来说,我们测试的任何产品都是基于操作系统.比如我们每天都在使用的QQ软件,它有windows.ios.Android.Mac OS等版本,需要把QQ安装 ...
- 生信分析常用脚本(二)--SOAPdenovo
1.SOAPDenovo配置文件示例 软件下载安装和使用:http://soap.genomics.org.cn/soapdenovo.html asm.cfg #maximal read lengt ...
- 《笨方法学Python》加分题32
注意一下 range 的用法.查一下 range 函数并理解它在第 22 行(我的答案),你可以直接将 elements 赋值为 range(0, 6) ,而无需使用 for 循环?在 python ...
- HDU 2196.Computer 树形dp 树的直径
Computer Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Su ...
- super()调用父类构造方法
super()表示调用父类中的构造方法 1.子类继承父类,子类的构造方法的第一行,系统会默认编写super(),在调用子类的构造方法时,先调用父类的无参数构造方法 2.如果父类中只有有参数构造方法,那 ...