重新想象 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 属性, 部分控件 ...
随机推荐
- ASP.NET MVC 自定义路由中几个需要注意的小细节
本文主要记录在ASP.NET MVC自定义路由时,一个需要注意的参数设置小细节. 举例来说,就是在访问 http://localhost/Home/About/arg1/arg2/arg3 这样的自定 ...
- 实现 Dispose 方法
实现 Dispose 方法 MSDN 类型的 Dispose 方法应释放它拥有的所有资源.它还应该通过调用其父类型的 Dispose 方法释放其基类型拥有的所有资源.该父类型的 Dispose 方法应 ...
- 解决oracle 端口 1521 本机127可通 其他ip不通
http://wenku.baidu.com/link?url=8tRGGObqgLd6-yqprioIZSyluu9K0BgA29Lhx7F57pVDIHbMHVDNTa_SlEmVugGT4QJO ...
- Git Tips
撤销已经推送到远程仓库的最后一次提交,要小心这么操作,因为远程仓库还有别人在使用 $ git reset --hard HEAD^ $ git push -f origin master 从仓库中提出 ...
- java判断乱码
开发需要,判断乱码,baidu了一下,基本都是同一份代码 if (!Character.isLetterOrDigit(c)) { -> 这个有问题,中文文字被识别成字母及数字 ...
- smdkv210
参考:http://code.google.com/p/libyuv/issues/detail?id=295 ******************************************** ...
- Embedding Python in C
http://codextechnicanum.blogspot.com/2013/12/embedding-python-in-c-converting-c.html //Make some vec ...
- linux下 C++ 读取mat文件 MATLAB extern cyphon scipy 未完待续
1.使用Matlab的C扩展,需要用户安装matlab. g++ -L/media/exsoftware/MATLAB/R2013b/bin/glnxa64 -Wl,-rpath,/media/exs ...
- JavaScript封装Ajax(类JQuery中$.ajax()方法)
ajax.js (function(exports, document, undefined){ "use strict"; function Ajax(){ if(!(this ...
- JavaScript 属性描述符
属性描述符(Property Descriptor)是 ES5 之后出现的概念,顾名思义,它用于描述属性应该是什么样,例如是否只读,能否枚举,能否可配置等.所有对象属性均可使用属性描述符来定义. 属性 ...