[源码下载]

重新想象 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. Three levels at which any machine carrying out an Information-Processing task must be understood

    1. Computational theory What is the goal of computation, why is it appropriate, and what is the logi ...

  2. 修改windows密码后ssrs报错

    昨夜修改了windows的登录密码,第二日发现ssrs全部无法访问.显示filenotfound等错误.细想一下,应该是修改了windows的密码导致ssrs权限验证失败. 因此将ssrs的服务帐号修 ...

  3. easyui plugin——etreegrid:CRUD Treegrid

    昨天写了一个ko+easyui的同样的实现,感觉写的太乱,用起来十分麻烦,于是今天照着edatagrid,写了一个etreegrid,这样再用ko绑定就方便多了. 使用很简单,$(tableId).e ...

  4. saiku 无密码登陆

    公司想要使用saiku,希望没有密码直接可以使用,这样可以直接以iframe的形式嵌套到其他的系统中. 在网上搜索了很多,大致类似这篇博客介绍的:http://www.cnblogs.com/aviv ...

  5. RadioButton 的background属性表现特征

    对于radiaoButton,应该很多人都用过.下面看一个场景     上方时radiogroup,细致观察发现左1,文字开始位置和右1文字开始位置不同,这是为何呢? 查看布局: <RadioB ...

  6. [原]ffmpeg编译android 硬解码支持库 libstagefright

    最近花了一天时间将ffmpeg/tools/build_stagefright执行成功,主要是交叉编译所需要的各种动态库的支持没链接上,导致各种报错,基本上网络上问到的问题我都碰到了,特此记录下来. ...

  7. 快速开发~Rafy框架的初步认识

    当我们开始使用EF的同时,是不是就会更好的认识了其他的ORM框架,最近接触了Rafy的使用,感觉还是蛮有兴趣去学习的,虽然最初的我到现在看的并不深入,但是我个人感觉还是可以简单地做一些总结的啦,或许语 ...

  8. MyBatis知多少(12)私有数据库

    如果你从事软件开发工作有了一段时间的话,那么肯定听过关于“自己动手还是花钱购买” 的争论.该争论是说,针对一个业务问题,我们是应该自己动手构建自己的解决方案呢,还是应 该花钱购买一个声称已经解决了此问 ...

  9. JavaScript 属性描述符

    属性描述符(Property Descriptor)是 ES5 之后出现的概念,顾名思义,它用于描述属性应该是什么样,例如是否只读,能否枚举,能否可配置等.所有对象属性均可使用属性描述符来定义. 属性 ...

  10. 这些年你需要注意的SQL

    [20141114]这些年你需要注意的SQL *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bot ...