[源码下载]

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

作者:webabcd

介绍
重新想象 Windows 8.1 Store Apps 之新增控件

  • DatePicker - 日期选择控件
  • TimePicker - 时间选择控件

示例
1、演示 DatePicker 的应用
DatePickerDemo.xaml

<Page
x:Class="Windows81.Controls.DatePickerDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows81.Controls"
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" /> <!--
DatePicker - 日期选择控件(默认横排,需要竖排的话则设置 Orientation="Vertical" 即可)
Header - 控件的标题
DateChanged - 选中的日期发生变化时所触发的事件
-->
<DatePicker x:Name="datePicker" Header="Date" DateChanged="datePicker_DateChanged" Margin="0 20 0 0" /> <!--
通过格式模板(format templates)设置 DatePicker 的显示格式
-->
<DatePicker DayFormat="day" MonthFormat="month.numeric" YearFormat="year.abbreviated" Margin="0 20 0 0" /> <!--
通过格式模式(format patterns)设置 DatePicker 的显示格式
-->
<DatePicker DayFormat="{}{day.integer}({dayofweek.abbreviated})" MonthFormat="{}{month.integer(2)}" YearFormat="{}{year.full}" Margin="0 20 0 0" />
<DatePicker DayFormat="{}{day.integer}日 ({dayofweek.abbreviated})" MonthFormat="{}{month.integer(2)}月" YearFormat="{}{year.full}年" Margin="0 20 0 0" /> <!--
关于 format templates 和 format patterns 请参见:
http://msdn.microsoft.com/en-us/library/windows/apps/windows.globalization.datetimeformatting.datetimeformatter.aspx
--> </StackPanel>
</Grid> </Page>

DatePickerDemo.xaml.cs

/*
* DatePicker - 日期选择控件
*/ using System;
using Windows.Globalization;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; namespace Windows81.Controls
{
public sealed partial class DatePickerDemo : Page
{
public DatePickerDemo()
{
this.InitializeComponent(); this.Loaded += DatePickerDemo_Loaded;
} void DatePickerDemo_Loaded(object sender, RoutedEventArgs e)
{
// Date - DatePicker 控件当前显示的日期
datePicker.Date = DateTimeOffset.Now.AddMonths(); // MinYear - DatePicker 控件所允许选择的最小的年份
datePicker.MinYear = DateTimeOffset.Now.AddYears(-);
// MaxYear - DatePicker 控件所允许选择的最大的年份
datePicker.MaxYear = DateTimeOffset.Now.AddYears(); // YearVisible - 是否显示 year 选择框
datePicker.YearVisible = true;
// MonthVisible - 是否显示 month 选择框
datePicker.MonthVisible = true;
// DayVisible - 是否显示 day 选择框
datePicker.DayVisible = true; // CalendarIdentifier - DatePicker 控件所使用的日历系统(Gregorian, Hebrew, Hijri, Japanese, Julian, Korean, Taiwan, Thai, UmAlQura)
datePicker.CalendarIdentifier = CalendarIdentifiers.Gregorian;
} // DatePicker 控件所选择的日期发生了变化
private void datePicker_DateChanged(object sender, DatePickerValueChangedEventArgs e)
{
// e.OldDate - 原日期
// e.NewDate - 新日期
lblMsg.Text = e.NewDate.ToString("yyyy-MM-dd hh:mm:ss");
}
}
}

2、演示 TimePicker 的应用
TimePickerDemo.xaml

<Page
x:Class="Windows81.Controls.TimePickerDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows81.Controls"
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" /> <!--
TimePicker - 时间选择控件(默认横排,需要竖排的话则设置 Orientation="Vertical" 即可)
Header - 控件的标题
TimeChanged - 选中的时间发生变化时所触发的事件
-->
<TimePicker Name="timePicker" Header="Time" TimeChanged="timePicker_TimeChanged" Margin="0 20 0 0" /> <TimePicker Name="timePicker2" Header="Time" Margin="0 20 0 0" /> </StackPanel>
</Grid>
</Page>

TimePickerDemo.xaml.cs

/*
* TimePicker - 时间选择控件
*/ using System;
using Windows.Globalization;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; namespace Windows81.Controls
{
public sealed partial class TimePickerDemo : Page
{
public TimePickerDemo()
{
this.InitializeComponent(); this.Loaded += TimePickerDemo_Loaded;
} void TimePickerDemo_Loaded(object sender, RoutedEventArgs e)
{
// Time - TimePicker 控件当前显示的时间
timePicker.Time = new TimeSpan(, , ); // MinuteIncrement - 分钟选择框的分钟增量(0, 15, 30, 45)
timePicker.MinuteIncrement = ; // ClockIdentifier - 小时制式,ClockIdentifiers.TwelveHour(12HourClock),12 小时制
timePicker.ClockIdentifier = ClockIdentifiers.TwelveHour;
// ClockIdentifier - 小时制式,ClockIdentifiers.TwentyFourHour(24HourClock),24 小时制
timePicker2.ClockIdentifier = ClockIdentifiers.TwentyFourHour;
} // TimePicker 控件所选择的时间发生变化时所触发的事件
private void timePicker_TimeChanged(object sender, TimePickerValueChangedEventArgs e)
{
// e.OldTime - 原时间
// e.NewTime - 新时间
lblMsg.Text = e.NewTime.ToString("c");
}
}
}

OK
[源码下载]

重新想象 Windows 8.1 Store Apps (73) - 新增控件: DatePicker, TimePicker的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

  8. 重新想象 Windows 8.1 Store Apps (78) - 控件增强: ScrollViewer, FlipView, Popup

    [源码下载] 重新想象 Windows 8.1 Store Apps (78) - 控件增强: ScrollViewer, FlipView, Popup 作者:webabcd 介绍重新想象 Wind ...

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

    [源码下载] 重新想象 Windows 8.1 Store Apps (79) - 控件增强: MediaElement, Frame 作者:webabcd 介绍重新想象 Windows 8.1 St ...

随机推荐

  1. WP-PostViews的安装和设置方法

    wordpress本身并没有文章浏览统计功能,必须借助插件.想要知道自己的文章被多数访客浏览,或者访客对哪些文章或者哪类文章更加有兴趣,这就是文章统计的重要性了.WP-PostViews插件是哥不错的 ...

  2. Oracle 数据库表同步方法浅议

    总结一下Oracle数据库表级别的复制同步 一.通过触发器进行表的复制 原理,是监听表上都某一字段进行的DML操作,然后得到DML操作的数据,重新在另一个表上执行DML操作. 优点: 简单,编写一个触 ...

  3. C++虚函数与虚函数表

    多态性可分为两类:静态多态和动态多态.函数重载和运算符重载实现的多态属于静态多态,动态多态性是通过虚函数实现的. 每个含有虚函数的类有一张虚函数表(vtbl),表中每一项是一个虚函数的地址, 也就是说 ...

  4. 计算A/3,不用除法

    int DividedBy3(int A) { ; ; i <= ; i += ) p += A << i; return (-p); }

  5. 读取并创建excel文件(.xls)

    第三方库,附件 缺点:该库只支持.xls文件的操作 1.读取excel文件 例子: try { /** * 后续考虑问题,比如Excel里面的图片以及其他数据类型的读取 **/ InputStream ...

  6. C#的设计模式分为3大类23种

    创建型: 1. 单件模式(Singleton Pattern) 2. 抽象工厂(Abstract Factory) 3. 建造者模式(Builder) 4. 工厂方法模式(Factory Method ...

  7. 打开jnlp Faild to validate certificate, the application will not be executed.

    今天连jenkins, 本来好好的,只是我在一台机器上一直不断的启动不同的jnlp,绑定不同命名的slave, 然后突然就报错了, 如下截图所示:

  8. Changing Project Binding to Surround SCM Integration Provider with Visual Studio 2010

    Changing Project Binding to Surround SCM Integration Provider with Visual Studio 2010 Sarah Wigser t ...

  9. led显字风扇原理?

    神奇的是上面的图案居然会变,十分好奇,求告知原理?? 其实就是依靠转速计算出LED灯变化的频率.这点和老式CRT的显示原理差不多.比如说风扇的转速时60rpm就是每分钟60圈,每秒1圈(当然实际转速快 ...

  10. C#基础课程之六(临时表)DataTable使用方法

    DataTable 用法:赋取值操作,及报错情况 dataTable.Columns.Add("Name"); //Columns 对象获取该集合的全部列,添加列名. 默认stri ...