[源码下载]

重新想象 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, 日历, 自定义锁屏系列图片的更多相关文章

  1. 重新想象 Windows 8.1 Store Apps 系列文章索引

    [源码下载] [重新想象 Windows 8 Store Apps 系列文章] 重新想象 Windows 8.1 Store Apps 系列文章索引 作者:webabcd 1.重新想象 Windows ...

  2. 重新想象 Windows 8.1 Store Apps (93) - 控件增强: GridView, ListView

    [源码下载] 重新想象 Windows 8.1 Store Apps (93) - 控件增强: GridView, ListView 作者:webabcd 介绍重新想象 Windows 8.1 Sto ...

  3. 重新想象 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 ...

  4. 重新想象 Windows 8.1 Store Apps (72) - 新增控件: AppBar, CommandBar

    [源码下载] 重新想象 Windows 8.1 Store Apps (72) - 新增控件: AppBar, CommandBar 作者:webabcd 介绍重新想象 Windows 8.1 Sto ...

  5. 重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker

    [源码下载] 重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker 作者:webabcd 介绍重新想象 Windows 8.1 ...

  6. 重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout

    [源码下载] 重新想象 Windows 8.1 Store Apps (74) - 新增控件: Flyout, MenuFlyout, SettingsFlyout 作者:webabcd 介绍重新想象 ...

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

    [源码下载] 重新想象 Windows 8.1 Store Apps (75) - 新增控件: Hub, Hyperlink 作者:webabcd 介绍重新想象 Windows 8.1 Store A ...

  8. 重新想象 Windows 8.1 Store Apps (76) - 新增控件: SearchBox

    [源码下载] 重新想象 Windows 8.1 Store Apps (76) - 新增控件: SearchBox 作者:webabcd 介绍重新想象 Windows 8.1 Store Apps 之 ...

  9. 重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件增加了 PlaceholderText 属性

    [源码下载] 重新想象 Windows 8.1 Store Apps (77) - 控件增强: 文本类控件的增强, 部分控件增加了 Header 属性和 HeaderTemplate 属性, 部分控件 ...

随机推荐

  1. 查看JAVA进程中哪个线程CPU消耗最高

    一,在centos linux 上查看进程占用cpu过高 top  shift+h 查看哪个进程程消耗最高     二,查看JAVA进程中哪个线程消耗最高   2.1 导出java运行的线程信息   ...

  2. Arduino 学习

    Arduino 背景可以参考官方网站www.arduino.cc 先看一个最简单的示例程序: 打开 Arduino IDE , 选择菜单:文件 -> 示例 -> 01.Basics -&g ...

  3. 怎样在EPLAN P8里创建自己想要的电气元件符号

    1.打开Eplan P8 ,新建一个名为"新项目"的项目,然后选择菜单"工具"----"主数据"-----"符号库"-- ...

  4. C#读取物理网卡信息及其对应的IP地址

    using Microsoft.Win32; using System; using System.Collections; using System.Collections.Generic; usi ...

  5. 国行手机安装GOOGLE PLAY

    原文地址:http://blog.sina.com.cn/s/blog_68cff87b0101a96k.html 相信国行的手机都是没有google Play 功能的吧,相比其它国外的手机,功能上逊 ...

  6. php读取csv文件,在linux上出现中文读取不到的情况 解决方法

    今,php读取csv文件,在linux上出现中文读取不到的情况,google,后找到解决办法<?phpsetlocale(LC_ALL, 'zh_CN');$row = 1;$handle = ...

  7. POJ 2887 Big String(块状链表)

    题目大意 给一个字符串,长度不超过 106,有两种操作: 1. 在第 i 个字符的前面添加一个字符 ch 2. 查询第 k 个位置是什么字符 操作的总数不超过 2000 做法分析 好多不同的做法都可以 ...

  8. 实战:ajax带参数请求slim API

    restful api 支持get,post,put,delete等方法,那么jquery客户端怎么去实现呢?涉及到跨域又怎么办? 很多时候需要传递一个token(api_key) 去识别用户身份,获 ...

  9. 数据结构 - 归并排序(merging sort)

    归并排序(merging sort): 包含2-路归并排序, 把数组拆分成两段, 使用递归, 将两个有序表合成一个新的有序表. 归并排序(merge sort)的时间复杂度是O(nlogn), 实际效 ...

  10. VPN有什么用?(转载)

    VPN有什么用?转载自:http://www.chinaz.com/web/2012/0320/240819.shtml 当你非常非常想访问一个国外的网站,而这个网站被防火墙屏蔽的时候,你应该怎么做呢 ...