重新想象 Windows 8.1 Store Apps (92) - 其他新特性: CoreDispatcher, 日历, 自定义锁屏系列图片
作者:webabcd
介绍
重新想象 Windows 8.1 Store Apps 之其他新特性
- CoreDispatcher 的新特性
- “日历”的相关操作
- 自定义锁屏时需要显示的系列图片
示例
1、演示 CoreDispatcher 在 win8.1 中的新特性
CoreDispatcherDemo.xaml.cs
/*
* 演示 CoreDispatcher 在 win8.1 中的新特性
*
* 关于几个 Core 的基础请参见:http://www.cnblogs.com/webabcd/archive/2013/11/11/3417379.html
*/ using System;
using Windows.UI.Xaml.Controls; namespace Windows81.Other
{
public sealed partial class CoreDispatcherDemo : Page
{
public CoreDispatcherDemo()
{
this.InitializeComponent(); this.Loaded += CoreDispatcherDemo_Loaded;
} async void CoreDispatcherDemo_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
// CoreDispatcher - 消息调度器
Windows.UI.Core.CoreDispatcher coreDispatcher = Windows.UI.Xaml.Window.Current.Dispatcher; // 优先级从高到低排序:
// 1、本地代码中的 SendMessage
// 2、CoreDispatcherPriority.High
// 3、CoreDispatcherPriority.Normal
// 4、所有设备输入消息
// 5、CoreDispatcherPriority.Low
// 6、CoreDispatcherPriority.Idle(一般用于后台任务)
await coreDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
{
// 调用 coreDispatcher 所在的线程
}); // 以下为 win8.1 新增 // 获取或设置当前 CoreDispatcher 的优先级
// coreDispatcher.CurrentPriority // 当前 CoreDispatcher 中的任务是否需要让步(即任务队列中是否存在更高优先级的任务,或指定的优先级及其以上的任务)
// coreDispatcher.ShouldYield()
// coreDispatcher.ShouldYield(CoreDispatcherPriority priority)
}
}
}
2、演示“日历”的相关操作
AppointmentDemo.xaml
<Page
x:Class="Windows81.Other.AppointmentDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows81.Other"
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" /> <Button Name="btnAddAppointment" Content="add appointment" Click="btnAddAppointment_Click" Margin="0 10 0 0" /> <Button Name="btnShowAppointment" Content="show appointment" Click="btnShowAppointment_Click" Margin="0 10 0 0" /> </StackPanel>
</Grid>
</Page>
AppointmentDemo.xaml.cs
/*
* 演示“日历”的相关操作
*/ using System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.ApplicationModel.Appointments;
using Windows.Foundation;
using Windows.UI.Xaml.Media; namespace Windows81.Other
{
public sealed partial class AppointmentDemo : Page
{
public AppointmentDemo()
{
this.InitializeComponent();
} private async void btnAddAppointment_Click(object sender, RoutedEventArgs e)
{
// 实例化一个 Appointment 对象
var appointment = new Appointment(); // 约会的开始时间
var startTime = new DateTimeOffset(, , , , , , TimeZoneInfo.Local.GetUtcOffset(DateTime.Now));
appointment.StartTime = startTime; // 约会的主题(不能超过 255 字符)
appointment.Subject = "情人节约会"; // 约会的地点(不能超过 32768 字符)
appointment.Location = "家里"; // 约会的详细内容(不能超过 1073741823 字符)
appointment.Details = "在家里做方便面吃,庆祝情人节"; // 约会的持续时间
appointment.Duration = TimeSpan.FromMinutes(); // 约会是否会持续一整天
appointment.AllDay = false; // 提醒(提醒时间点为:约会开始时间减去此属性指定的时间),如果此属性设置为 null 则不提醒
appointment.Reminder = TimeSpan.FromMinutes(); // 约会参与者的繁忙状态(AppointmentBusyStatus 枚举)
appointment.BusyStatus = AppointmentBusyStatus.Free; // 约会的隐私程度(AppointmentSensitivity 枚举:Public, Private)
appointment.Sensitivity = AppointmentSensitivity.Private; // Uri
appointment.Uri = new System.Uri("http://webabcd.cnblogs.com"); // 约会的组织者
var organizer = new AppointmentOrganizer();
organizer.DisplayName = "webabcd"; // 组织者的显示名称(不能超过 255 字符)
organizer.Address = "email@mail.com"; // 组织者的地址(不能超过 321 字符)
// 指定约会的组织者
appointment.Organizer = organizer; // 约会参与者
var invitee = new AppointmentInvitee();
invitee.DisplayName = "abc"; // 约会参与者的显示名称(不能超过 255 字符)
invitee.Address = "email2@mail.com"; // 约会参与者的地址(不能超过 321 字符)
invitee.Role = AppointmentParticipantRole.OptionalAttendee; // 约会参与者的赴约选项
invitee.Response = AppointmentParticipantResponse.Accepted; // 约会参与者的赴约响应
// 添加一个约会参与者
// appointment.Invitees.Add(invitee); // 循环约会
var recurrence = new AppointmentRecurrence();
recurrence.Unit = AppointmentRecurrenceUnit.Daily; // 循环约会的发生频率(AppointmentRecurrenceUnit 枚举)
recurrence.Interval = ; // 循环约会的发生间隔(比如 Unit 为 AppointmentRecurrenceUnit.Daily,Interval 为 2 则代表每两天发生一次)
recurrence.Occurrences = ; // 循环约会的循环次数(null 代表不限制)
recurrence.Until = null; // 循环约会的截止时间(null 代表不限制)
recurrence.WeekOfMonth = AppointmentWeekOfMonth.First; // 循环约会发生在月中的第几周
recurrence.DaysOfWeek = AppointmentDaysOfWeek.Sunday | AppointmentDaysOfWeek.Monday; // 循环约会发生在星期几(flags 类型的枚举)
recurrence.Month = ; // 约会发生的月
recurrence.Day = ; // 约会发生的日
// 指定循环约会
// appointment.Recurrence = recurrence; var rect = GetElementRect(sender as FrameworkElement);
// 在指定的位置弹出日历对话框,用于让用户确认是否将相关的约会加入日历(返回值为约会的标识,更新及删除约会都需要用到此标识)
String appointmentId = await AppointmentManager.ShowAddAppointmentAsync(appointment, rect, Windows.UI.Popups.Placement.Default);
if (appointmentId != String.Empty) // 约会标识,用于更新和删除约会
{
lblMsg.Text = "Appointment Id: " + appointmentId;
}
else
{
lblMsg.Text = "Appointment not added.";
} // 相关的对话框还有如下几个:
// await AppointmentManager.ShowReplaceAppointmentAsync(); // 更新约会
// await AppointmentManager.ShowRemoveAppointmentAsync(); // 删除约会
} private async void btnShowAppointment_Click(object sender, RoutedEventArgs e)
{
var dateToShow = new DateTimeOffset(, , , , , , TimeZoneInfo.Local.GetUtcOffset(DateTime.Now));
var duration = TimeSpan.FromDays(); // 显示指定的时间段内的日历
// 第一个参数:开始时间
// 第二个参数:从开始时间计算的时间跨度
await AppointmentManager.ShowTimeFrameAsync(dateToShow, duration);
} private Rect GetElementRect(FrameworkElement element)
{
GeneralTransform buttonTransform = element.TransformToVisual(null);
Point point = buttonTransform.TransformPoint(new Point());
return new Rect(point, new Size(element.ActualWidth, element.ActualHeight));
}
}
}
3、演示如何自定义锁屏时需要显示的系列图片(需要指定一个 rss 文件地址)
LockScreenWallpapers.xaml.cs
/*
* 演示如何自定义锁屏时需要显示的系列图片(需要指定一个 rss 文件地址)
*
*
* 关于设置和获取锁屏单张图片,请参见:http://www.cnblogs.com/webabcd/archive/2013/09/12/3316073.html
*
*
* 注:
* 1、本例使用的 rss 文件请参见:WebServer 项目下的 wallpapers.xml 文件
* 2、在“设置”->“锁屏界面”中可以设置是否打开锁屏图片的幻灯片显示,其中幻灯片图片提供者的名字是 rss 文件中的 title
*/ using System;
using Windows.System.UserProfile;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; namespace Windows81.Other
{
public sealed partial class LockScreenWallpapers : Page
{
public LockScreenWallpapers()
{
this.InitializeComponent();
} private async void btnDemo_Click(object sender, RoutedEventArgs e)
{
// 指定锁屏系列图片的数据源(一个 rss 数据),并弹出对话框让用户确认
SetImageFeedResult result = await LockScreen.RequestSetImageFeedAsync(new Uri("http://localhost:39630/wallpapers.xml"));
if (result == SetImageFeedResult.Success)
{
lblMsg.Text = "指定的 url 已经被设置为锁屏系列图片的数据源";
}
else if (result == SetImageFeedResult.ChangeDisabled)
{
lblMsg.Text = "安全策略不允许显示锁屏系列图片";
}
else if (result == SetImageFeedResult.UserCanceled)
{
lblMsg.Text = "用户取消了";
} // 取消锁屏系列图片
// LockScreen.TryRemoveImageFeed();
}
}
}
OK
[源码下载]
重新想象 Windows 8.1 Store Apps (92) - 其他新特性: CoreDispatcher, 日历, 自定义锁屏系列图片的更多相关文章
- 重新想象 Windows 8.1 Store Apps 系列文章索引
[源码下载] [重新想象 Windows 8 Store Apps 系列文章] 重新想象 Windows 8.1 Store Apps 系列文章索引 作者:webabcd 1.重新想象 Windows ...
- 重新想象 Windows 8.1 Store Apps (93) - 控件增强: GridView, ListView
[源码下载] 重新想象 Windows 8.1 Store Apps (93) - 控件增强: GridView, ListView 作者:webabcd 介绍重新想象 Windows 8.1 Sto ...
- 重新想象 Windows 8.1 Store Apps (81) - 控件增强: WebView 之加载本地 html, 智能替换 html 中的 url 引用, 通过 Share Contract 分享 WebView 中的内容, 为 WebView 截图
[源码下载] 重新想象 Windows 8.1 Store Apps (81) - 控件增强: WebView 之加载本地 html, 智能替换 html 中的 url 引用, 通过 Share Co ...
- 重新想象 Windows 8.1 Store Apps (72) - 新增控件: AppBar, CommandBar
[源码下载] 重新想象 Windows 8.1 Store Apps (72) - 新增控件: AppBar, CommandBar 作者:webabcd 介绍重新想象 Windows 8.1 Sto ...
- 重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker
[源码下载] 重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker 作者:webabcd 介绍重新想象 Windows 8.1 ...
- 重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout
[源码下载] 重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout 作者:webabcd 介绍重新想象 ...
- 重新想象 Windows 8.1 Store Apps (75) - 新增控件: Hub, Hyperlink
[源码下载] 重新想象 Windows 8.1 Store Apps (75) - 新增控件: Hub, Hyperlink 作者:webabcd 介绍重新想象 Windows 8.1 Store A ...
- 重新想象 Windows 8.1 Store Apps (76) - 新增控件: SearchBox
[源码下载] 重新想象 Windows 8.1 Store Apps (76) - 新增控件: SearchBox 作者:webabcd 介绍重新想象 Windows 8.1 Store Apps 之 ...
- 重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件增加了 PlaceholderText 属性
[源码下载] 重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件 ...
随机推荐
- Tomcat抛出异常:ClientAbortException: java.net.SocketException: Connection
在做一个小网站的时候,写了一个通过servlet实现文件下载功能的页面.当我点击超级练级,弹出下载对话框,点击保存正常下载,不会出现任何问题,当我我点击取消,服务器端就出现如下提示: ClientAb ...
- GitHub上排名前100的Android开源库介绍(来自github)
本项目主要对目前 GitHub 上排名前 100 的 Android 开源库进行简单的介绍,至于排名完全是根据 GitHub 搜索 Java 语言选择 (Best Match) 得到的结果,然后过滤了 ...
- PHP操作MongoDB学习(转)
1 mongodb启动时,设置启动项 C:\>mongodb\bin\mongod --config C:\mongodb.conf 其中mongodb.conf为: dbpath = ...
- (笔记)Linux内核学习(五)之中断推后处理机制
一 中断 硬件通过中断与操作系统进行通信,通过对硬件驱动程序处注册中断处理程序,快速响应硬件的中断. 硬件中断优先级很高,打断当前正在执行的程序.有两种情况: 硬件中断在中断处理程序中处理 硬件中断延 ...
- java&postgresql时区总结
介绍这篇文章之前,首先回答一个问题,以前都没有时区的概念,程序也写的好好的,为什么要计算时区哪?举个例子,比如有一个订单的时间是:2015-07-04 11:28:19,那么咋一看没什么问题,可是如果 ...
- mongodb存储过程
MongoDB支持存储过程的使用,它的存储过程是用javascript实现的,被存在于system.js表中,可以接收和输出参数,返回执行存储过程的状态值,也可以嵌套调用. 所以我理解的Mon ...
- vxworks下网络编程一:网络字节序问题
inet_addr("192.168.1.1");//返回网络字节序整型ip地址inet_ntoa(saddr);//将包含网络字节序整型ip地址的in_addr对象转换成本地ch ...
- delphi7的新生,参与分布式应用开发,调用RESTful API,Json的应用
前言: 1.公司delphi7开发的传统软件还活得好好的,但是大家都知道delphi早已经日落西山了,现在成了后进.追随者.细细算了已经6.7不用了.新的delphixe7呢,没有时间成本去适应和研究 ...
- jsp页面间传递参数 中文乱码问题(zz)
jsp页面间传递参数 中文乱码问题 1.传递参数 var url = "*****Test.jsp?param1="+encodeURI(encodeURI(str));//对 ...
- 比特(bit)与字节(byte)区别,站位比较
“字节”(Byte) “比特”(Bit) 当你进行网络下载的时候它们会经常出现,同时你获取的速度指示也都以比特/每秒或者字节/每秒来显示. 现在就来弄清楚比特(Bit).字节(Byte)和千字节(Kb ...