原文:重新想象 Windows 8.1 Store Apps (85) - 警报通知(闹钟), Tile 的新特性

[源码下载]

重新想象 Windows 8.1 Store Apps (85) - 警报通知(闹钟), Tile 的新特性

作者:webabcd

介绍
重新想象 Windows 8.1 Store Apps 之通知的新特性

  • 警报通知(闹钟)
  • Tile 的新特性

示例
1、演示 win8.1 中新增的警报 toast(闹钟)
AlarmToast.xaml

<Pagex:Class="Windows81.Notification.AlarmToast"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="using:Windows81.Notification"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="120 0 0 0"><TextBlock Name="lblMsg" FontSize="14.667" Margin="0 10 0 0" /></StackPanel></Grid>
</Page>

AlarmToast.xaml.cs

/** 演示 win8.1 中新增的警报 toast(闹钟)* * 关于 toast 的基础请参见:http://www.cnblogs.com/webabcd/archive/2013/06/20/3145356.html* * * 注:* 1、需要在 manifest 中设置支持 toast 通知和锁屏通知* 2、需要在 manifest 中的 Application/Extensions 内做如下设置* <!--声明此 app 是一个“闹钟”应用,其会出现在“设置”->“电脑和设备”->“锁屏应用”->“选择要显示提醒的应用”列表中--><m2:Extension Category="windows.alarm" /><!--为了演示 Notification/AlarmToast 需要如下设置一个后台任务--><Extension Category="windows.backgroundTasks" EntryPoint="SampleForAlarmToast"><BackgroundTasks><Task Type="audio" /><Task Type="timer" /></BackgroundTasks></Extension>* 3、系统静音也能播放声音* 4、不受免打扰时间的限制*/using System;
using Windows.ApplicationModel.Background;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;namespace Windows81.Notification
{public sealed partial class AlarmToast : Page{public AlarmToast(){this.InitializeComponent();this.Loaded += AlarmToast_Loaded;}protected async override void OnNavigatedTo(NavigationEventArgs e){try{// 向系统请求成为闹钟应用的权限,会弹出确认对话框await AlarmApplicationManager.RequestAccessAsync().AsTask();// 获取当前应用程序的成为闹钟应用的权限(AlarmAccessStatus 枚举)//     Unspecified - 用户未响应应用程序设置警报的权限请求//     AllowedWithWakeupCapability - 用户已经为应用程序授予设置警报的权限,并且警报可以将计算机从待机状态唤醒//     AllowedWithoutWakeupCapability - 用户已经为应用程序授予设置警报的权限,但是警报无法将计算机从待机状态唤醒//     Denied - 用户已拒绝该应用程序设置警报的权限AlarmAccessStatus alarmAccessStatus = AlarmApplicationManager.GetAccessStatus();lblMsg.Text = alarmAccessStatus.ToString();}catch (Exception ex){lblMsg.Text = ex.ToString();}}void AlarmToast_Loaded(object sender, RoutedEventArgs e){// 关于 toast 通知详见:http://www.cnblogs.com/webabcd/archive/2013/06/20/3145356.htmlstring toastXmlString ="<toast duration=\"long\">\n" +"<visual>\n" +"<binding template=\"ToastText02\">\n" +"<text id=\"1\">text1</text>\n" +"<text id=\"2\">text2</text>\n" +"</binding>\n" +"</visual>\n" +"<commands scenario=\"alarm\">\n" + // 除了 alarm 还有 incomingCall"<command id=\"snooze\"/>\n" + // snooze 代表在闹钟 toast 中显示“暂停”按钮(小睡一会)"<command id=\"dismiss\"/>\n" + // dismiss 代表在闹钟 toast 中显示“取消”按钮"</commands>\n" +// 闹钟铃声: Notification.Default, Notification.IM, Notification.Mail, Notification.Reminder, Notification.SMS, Notification.Looping.Alarm, Notification.Looping.Alarm2, Notification.Looping.Alarm3, Notification.Looping.Alarm4, Notification.Looping.Alarm5, Notification.Looping.Alarm6, Notification.Looping.Alarm7, Notification.Looping.Alarm8, Notification.Looping.Alarm9, Notification.Looping.Alarm10, Notification.Looping.Call, Notification.Looping.Call2, Notification.Looping.Call3, Notification.Looping.Call4, Notification.Looping.Call5, Notification.Looping.Call6, Notification.Looping.Call7, Notification.Looping.Call8, Notification.Looping.Call9, Notification.Looping.Call10"<audio src=\"Notification.Looping.Alarm2\" loop=\"true\" />\n" + "</toast>\n";var toastDOM = new Windows.Data.Xml.Dom.XmlDocument();toastDOM.LoadXml(toastXmlString);var toastNotifier = Windows.UI.Notifications.ToastNotificationManager.CreateToastNotifier();// 闹钟 toast 提示出现后,如果点击“暂停”(snooze)按钮,则第 3 个参数指定的时间过后继续弹出闹钟 toast,本例是 120 秒var customAlarmScheduledToast = new Windows.UI.Notifications.ScheduledToastNotification(toastDOM, DateTime.Now.AddSeconds(5), TimeSpan.FromSeconds(120), 0); toastNotifier.AddToSchedule(customAlarmScheduledToast);}}
}

2、win8.1 中的 tile 模板增加到 75 个
Tile.xaml

<Pagex:Class="Windows81.Notification.Tile"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:local="using:Windows81.Notification"xmlns:d="http://schemas.microsoft.com/expression/blend/2008"xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"mc:Ignorable="d"><Grid Background="Transparent"><Grid.Resources><Style x:Key="ItemTitleStyle" TargetType="TextBlock"><Setter Property="FontSize" Value="14.667"/></Style><ItemsPanelTemplate x:Key="StoreFrontGridItemsPanelTemplate"><WrapGrid MaximumRowsOrColumns="3" VerticalChildrenAlignment="Top" HorizontalChildrenAlignment="Left"/></ItemsPanelTemplate><Style x:Key="StoreFrontTileStyle"  TargetType="GridViewItem"><Setter Property="FontFamily" Value="Segoe UI" /><Setter Property="Height" Value="310" /><Setter Property="Width" Value="310" /><Setter Property="Padding" Value="0" /><Setter Property="Margin" Value="5" /><Setter Property="HorizontalContentAlignment" Value="Left" /><Setter Property="VerticalContentAlignment" Value="Top" /><Setter Property="BorderThickness" Value="0"/><Setter Property="TabNavigation" Value="Local" /></Style><DataTemplate x:Key="StoreFrontTileTemplate"><Grid HorizontalAlignment="Left" Background="Transparent"><StackPanel Orientation="Vertical"><TextBlock TextWrapping="Wrap" VerticalAlignment="Center" Text="{Binding FileName}" HorizontalAlignment="Left" /><Image Source="{Binding Path}" Stretch="None" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0,10,0,0"/></StackPanel></Grid></DataTemplate></Grid.Resources><!--显示 75 种不同的 Tile 模板--><GridView x:Name="gridView" Margin="120 0 0 0"ItemTemplate="{StaticResource StoreFrontTileTemplate}"ItemContainerStyle="{StaticResource StoreFrontTileStyle}"ItemsPanel="{StaticResource StoreFrontGridItemsPanelTemplate}"BorderBrush="LightGray" VerticalAlignment="Top"ScrollViewer.VerticalScrollBarVisibility="Auto"ScrollViewer.HorizontalScrollBarVisibility="Auto" SelectionMode="None" /></Grid>
</Page>

Tile.xaml.cs

/** win8.1 中的 tile 模板增加到 75 个* * * 关于 tile 的基础请参见:http://www.cnblogs.com/webabcd/archive/2013/06/24/3151864.html* * * win 8.1 中 tile 的新特性如下:* 1、tile 分 4 种:小 = Square70x70, 中等 = Square150x150, 长方形 = Wide310x150, 大 = Square310x310* 2、可以在 manifest 中指定 app 安装后默认的 tile 类型* 3、使用 tile 模板时,其命名规则也变了,参见 NotificationsExtensions 项目(比如 win8 中的 TileSquareImage 在 win8.1 中变为了 TileSquare150x150Image)* 4、tile 基础(通过 NotificationsExtensions 创建)参见:http://www.cnblogs.com/webabcd/archive/2013/06/24/3151864.html* 5、tile 基础(通过手工构造 xml)参见:http://www.cnblogs.com/webabcd/archive/2013/06/17/3139740.html* 6、如果想要支持 Square310x310,则必须要支持 Wide310x150* 7、建议为缩放比例 0.8x、1x、1.4x 和 1.8x 提供相对应的资源,以达到更好的显示效果* 8、tile 的通知队列,除了 TileUpdater.EnableNotificationQueue() 外还支持只在指定大小的 tile 上启用 tile 队列:TileUpdater.EnableNotificationQueueForSquare150x150(), TileUpdater.EnableNotificationQueueForSquare310x310(), TileUpdater.EnableNotificationQueueForWide310x150()* 9、新增 SecondaryTile.PhoneticName,可以指定 SecondaryTile 的名字的拼音,系统将据此排序 UI * 10、为了同时支持 win8 和 win8.1 新增了 fallback 属性,类似如下使用(找不到 TileSquare150x150Image 的话则用 TileSquareImage,找不到 TileWide310x150Image 的话则用 TileWideImage)
<tile><visual version="2"><binding template="TileSquare150x150Image" fallback="TileSquareImage" branding="None"><image id="1" src="Assets/Images/w6.png"/></binding><binding template="TileWide310x150Image" fallback="TileWideImage" branding="None"><image id="1" src="Assets/Images/sq5.png"/></binding><binding template="TileSquare310x310Image" branding="None"><image id="1" src="Assets/Images/sq6.png"/></binding></visual>
</tile>*/using System;
using System.Linq;
using Windows.ApplicationModel;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Navigation;namespace Windows81.Notification
{public sealed partial class Tile : Page{public Tile(){this.InitializeComponent();}protected async override void OnNavigatedTo(NavigationEventArgs e){// Windows81/Notification/tiles 文件夹内 75 张图片分别用于演示 Tile 的 75 种模板var folder = await Package.Current.InstalledLocation.GetFolderAsync(@"Notification\tiles");var files = await folder.GetFilesAsync();var dataSource = from p in filesselect new{FileName = p.DisplayName,Path = "ms-appx:///Notification/tiles/" + p.Name};gridView.ItemsSource = dataSource;}}
}

OK
[源码下载]

重新想象 Windows 8.1 Store Apps (85) - 警报通知(闹钟), Tile 的新特性相关推荐

  1. 重新想象 Windows 8.1 Store Apps (79) - 控件增强: MediaElement, Frame

    重新想象 Windows 8.1 Store Apps (79) - 控件增强: MediaElement, Frame 原文:重新想象 Windows 8.1 Store Apps (79) - 控 ...

  2. 重新想象 Windows 8.1 Store Apps (89) - 通信的新特性: 下载数据, 上传数据, 上传文件...

    重新想象 Windows 8.1 Store Apps (89) - 通信的新特性: 下载数据, 上传数据, 上传文件 原文:重新想象 Windows 8.1 Store Apps (89) - 通信 ...

  3. 重新想象 Windows 8.1 Store Apps (75) - 新增控件: Hub, Hyperlink

    原文:重新想象 Windows 8.1 Store Apps (75) - 新增控件: Hub, Hyperlink [源码下载] 重新想象 Windows 8.1 Store Apps (75) - ...

  4. 重新想象 Windows 8.1 Store Apps (91) - 后台任务的新特性: 下载和上传的新特性, 程序启动前预下载网络资源, 后台任务的其它新特性...

    原文:重新想象 Windows 8.1 Store Apps (91) - 后台任务的新特性: 下载和上传的新特性, 程序启动前预下载网络资源, 后台任务的其它新特性 [源码下载] 重新想象 Wind ...

  5. Windows 7驱动开发系列(一)--前言WIN7的新特性

    随着工作时间的增加,感觉自己技术越做越向DESIGN发展哈哈,一些具体的工作反而少了很多,所以做为总结呢,把自己对WINDOWS驱动分享一下,当然了水平及时间都有限欢迎大家一起讨论. 其实在网上看招聘 ...

  6. Kinect开发笔记之二Kinect for Windows 2.0新特性

    这是本博客的第一篇翻译文档,笔者已经苦逼的竭尽全力的在翻译了,但无奈英语水平也是很有限,不对或者不妥当不准确的地方必然会有,还恳请大家留言或者邮件我以批评指正,我会虚心接受.谢谢大家.         ...

  7. 重新想象 Windows 8 Store Apps (61) - 通信: http, oauth

    重新想象 Windows 8 Store Apps (61) - 通信: http, oauth 原文:重新想象 Windows 8 Store Apps (61) - 通信: http, oauth ...

  8. 重新想象 Windows 8 Store Apps (10) - 控件之 ScrollViewer 特性: Chaining, Rail, Inertia, Snap, Zoom...

    原文:重新想象 Windows 8 Store Apps (10) - 控件之 ScrollViewer 特性: Chaining, Rail, Inertia, Snap, Zoom [源码下载] ...

  9. 重新想象 Windows 8 Store Apps (49) - 输入: 获取输入设备信息, 虚拟键盘, Tab 导航, Pointer, Tap, Drag, Drop...

    重新想象 Windows 8 Store Apps (49) - 输入: 获取输入设备信息, 虚拟键盘, Tab 导航, Pointer, Tap, Drag, Drop 原文:重新想象 Window ...

最新文章

  1. OBS源代码阅读笔记
  2. 翻译们又要失业?Facebook最新无监督机器翻译成果,BLEU提升10个点!
  3. DL之DNN:利用MultiLayerNetExtend模型【6*100+ReLU+SGD,dropout】对Mnist数据集训练来抑制过拟合
  4. Codeforces Round #321 (Div. 2) E
  5. vector C++ 详细用法
  6. WPF程序将DLL嵌入到EXE的两种方法
  7. 1-docker 介绍
  8. 布客·ApacheCN 编程/后端/大数据/人工智能学习资源 2021.7
  9. jquery编写插件的三种方法
  10. hwclock设置日期_hwclock显示系统硬件时钟的日期和时间
  11. vue综合实例——音乐播放器(悦听player)
  12. chrome 自动操纵谷歌小恐龙
  13. java 运行器_[原创]我也来做一个最简单的Java2EXE的运行器
  14. 在这个大数据时代,如何保护好自己的隐私?
  15. docker 命令详解(二十四):push
  16. 汽车配件销售管理系统毕业设计
  17. 推荐几个不错的DOTNET控件网址
  18. 05.ESP8266连接网络
  19. 微商卖潮鞋怎么引流呢?微商如何精准引流?
  20. 一个完美网站的101项指标.第一部分.概述收藏一个完美网站的101项指标第一部分.概述...

热门文章

  1. angularjs 表单校验指令_angular4.0的模板式表单、响应式表单及其错误提示
  2. 淘宝客程序 —— 突破了传统淘宝客程序对自动采集商品收费的模式
  3. emlog程序音乐歌曲网源码
  4. 最全Linux安装Redis最新版
  5. HTML5: 利用SVG动画动态绘制文字轮廓边框线条
  6. 零基础 Amazon Web Services (AWS) 入门教程图文版(二)
  7. 背包——完全背包Warcraft III(哈理工1053)
  8. DNS服务器 安装部署 以及子域授权和转发
  9. 【会议/期刊】中科院推荐计算机领域人工智能方向会议和期刊列表
  10. Linux—解压缩命令总结(tar/zip)