背水一战 Windows 10 (44) - 控件(日期类): CalendarView, DatePicker, TimePicker
作者:webabcd
介绍
背水一战 Windows 10 之 控件(日期类)
- CalendarView
- DatePicker
- TimePicker
示例
1、CalendarView 的示例
Controls/DateControl/CalendarViewDemo.xaml
<Page
x:Class="Windows10.Controls.DateControl.CalendarViewDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.DateControl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" xmlns:common="using:Windows10.Common"> <Page.Resources>
<common:NullableBooleanToBooleanConverter x:Key="NullableBooleanToBooleanConverter" />
</Page.Resources> <Grid Background="Transparent">
<StackPanel Margin="10 0 10 10"> <CheckBox Name="chkIsOutOfScopeEnabled" Margin="5" Content="IsOutOfScopeEnabled" IsChecked="True" />
<CheckBox Name="chkIsGroupLabelVisible" Margin="5" Content="IsGroupLabelVisible" IsChecked="True" />
<CheckBox Name="chkIsTodayHighlighted" Margin="5" Content="IsTodayHighlighted" IsChecked="True" />
<ComboBox x:Name="cmbSelectionMode" Margin="5" PlaceholderText="SelectionMode" SelectionChanged="cmbSelectionMode_SelectionChanged">
<ComboBoxItem>None</ComboBoxItem>
<ComboBoxItem>Single</ComboBoxItem>
<ComboBoxItem>Multiple</ComboBoxItem>
</ComboBox>
<ComboBox x:Name="cmbDisplayMode" Margin="5" PlaceholderText="DisplayMode" SelectionChanged="cmbDisplayMode_SelectionChanged">
<ComboBoxItem>Month</ComboBoxItem>
<ComboBoxItem>Year</ComboBoxItem>
<ComboBoxItem>Decade</ComboBoxItem>
</ComboBox>
<ComboBox x:Name="cmbFirstDayOfWeek" Margin="5" PlaceholderText="FirstDayOfWeek" SelectionChanged="cmbFirstDayOfWeek_SelectionChanged">
<ComboBoxItem>Sunday</ComboBoxItem>
<ComboBoxItem>Monday</ComboBoxItem>
<ComboBoxItem>Tuesday</ComboBoxItem>
<ComboBoxItem>Wednesday</ComboBoxItem>
<ComboBoxItem>Thursday</ComboBoxItem>
<ComboBoxItem>Friday</ComboBoxItem>
<ComboBoxItem>Saturday</ComboBoxItem>
</ComboBox> <!--
CalendarView - 日历控件
IsOutOfScopeEnabled - 是否以不同的颜色显示范围外的日历项
IsGroupLabelVisible - 是否在月的第一天或年的第一月的日历项中显示月份或年份
IsTodayHighlighted - 是否高亮显示当天日历项
FirstDayOfWeek - 指定每周的第一天是周几
SelectionMode - 日历的选择模式(None - 禁止选择, Single - 单选, Multiple - 多选)
DisplayMode - 日历的显示模式(Month - 月, Year - 年, Decade - 十年)
Language - 日历上的显示语言
CalendarIdentifier - 控件使用的日历系统,一个字符串值,在 CalendarIdentifiers 类中有封装
SelectedDatesChanged - 选中的日期发生变化时触发的事件
CalendarViewDayItemChanging - 加载日历项时触发的事件 其他大部分属性都是用于配置显示样式的了,具体说明详见文档
另外,在 CalendarView 控件中没有属性可以直接设置当天日历项的背景色(在本例的 code-behind 中给出了解决办法)
-->
<CalendarView Name="calendarView" Margin="5"
IsOutOfScopeEnabled="{x:Bind chkIsOutOfScopeEnabled.IsChecked, Mode=TwoWay, Converter={StaticResource NullableBooleanToBooleanConverter}}"
IsGroupLabelVisible="{x:Bind chkIsGroupLabelVisible.IsChecked, Mode=TwoWay, Converter={StaticResource NullableBooleanToBooleanConverter}}"
IsTodayHighlighted="{x:Bind chkIsTodayHighlighted.IsChecked, Mode=TwoWay, Converter={StaticResource NullableBooleanToBooleanConverter}}"
FirstDayOfWeek="Sunday"
SelectionMode="Single"
DisplayMode="Month"
Language="zh-cn"
CalendarIdentifier="GregorianCalendar"
SelectedDatesChanged="calendarView_SelectedDatesChanged"
CalendarViewDayItemChanging="calendarView_CalendarViewDayItemChanging" /> </StackPanel>
</Grid>
</Page>
Controls/DateControl/CalendarViewDemo.xaml.cs
/*
* CalendarView - 日历控件(继承自 Control, 请参见 /Controls/BaseControl/ControlDemo/)
*
* CalendarViewDayItem - 日历项控件(继承自 Control, 请参见 /Controls/BaseControl/ControlDemo/)
* Date - 获取此日历项的日期(只读)
* IsBlackout - 此日历项是否不可用(通过 CalendarView 的 BlackoutForeground 属性可配置不可用日历项的前景色)
*/ using System;
using Windows.UI;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media; namespace Windows10.Controls.DateControl
{
public sealed partial class CalendarViewDemo : Page
{
public CalendarViewDemo()
{
this.InitializeComponent();
} private void cmbSelectionMode_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
calendarView.SelectionMode = (CalendarViewSelectionMode)Enum.Parse(typeof(CalendarViewSelectionMode), (e.AddedItems[] as ComboBoxItem).Content.ToString());
} private void cmbDisplayMode_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
calendarView.DisplayMode = (CalendarViewDisplayMode)Enum.Parse(typeof(CalendarViewDisplayMode), (e.AddedItems[] as ComboBoxItem).Content.ToString());
} private void cmbFirstDayOfWeek_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
calendarView.FirstDayOfWeek = (Windows.Globalization.DayOfWeek)Enum.Parse(typeof(Windows.Globalization.DayOfWeek), (e.AddedItems[] as ComboBoxItem).Content.ToString());
} // 加载日历项时触发的事件
private void calendarView_CalendarViewDayItemChanging(CalendarView sender, CalendarViewDayItemChangingEventArgs args)
{
// 如果当前加载的日历项时当天的话
if (args.Item.Date.Date.Equals(DateTime.Now.Date))
{
// 修改日历项的背景色(在 CalendarView 控件中没有属性可以直接设置当天日历项的背景色)
// 另外,还有一些日历项的样式无法通过 CalendarView 直接设置,那么都可以考虑像这样做
args.Item.Background = new SolidColorBrush(Colors.Orange);
}
} // 选中的日期发生变化时触发的事件
private void calendarView_SelectedDatesChanged(CalendarView sender, CalendarViewSelectedDatesChangedEventArgs args)
{
// args.RemovedDates - 之前被选中的日期集合
// args.AddedDates - 当前被选中的日期集合 // calendarView.SelectedDates - 当前被选中的日期集合
}
}
}
2、DatePicker 的示例
Controls/DateControl/DatePickerDemo.xaml
<Page
x:Class="Windows10.Controls.DateControl.DatePickerDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.DateControl"
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="10 0 10 10"> <TextBlock Name="lblMsg" /> <!--
DatePicker - 日期选择控件
Header - 可以设置一个纯文本,不能命中测试,空 Header 的话不会占用任何空间
HeaderTemplate - 可以将 Header 设置为任何 xaml,且支持命中测试
DateChanged - 选中的日期发生变化时触发的事件
Orientation - 经测试,无效
YearFormat, MonthFormat, DayFormat - 格式化年, 月, 日数据(支持 format templates 和 format patterns) 注:关于 format templates 和 format patterns 请参见
http://msdn.microsoft.com/en-us/library/windows/apps/windows.globalization.datetimeformatting.datetimeformatter.aspx
--> <DatePicker x:Name="datePicker" Header="Date" DateChanged="datePicker_DateChanged" Margin="5" Orientation="Vertical" /> <!--
通过格式模板(format templates)设置 DatePicker 的显示格式
-->
<DatePicker DayFormat="day" MonthFormat="month.numeric" YearFormat="year.abbreviated" Margin="5" /> <!--
通过格式模式(format patterns)设置 DatePicker 的显示格式
-->
<DatePicker DayFormat="{}{day.integer}({dayofweek.abbreviated})" MonthFormat="{}{month.integer(2)}" YearFormat="{}{year.full}" Margin="5" />
<DatePicker DayFormat="{}{day.integer}日 ({dayofweek.abbreviated})" MonthFormat="{}{month.integer(2)}月" YearFormat="{}{year.full}年" Margin="5" /> </StackPanel>
</Grid>
</Page>
Controls/DateControl/DatePickerDemo.xaml.cs
/*
* DatePicker - 日期选择控件(继承自 Control, 请参见 /Controls/BaseControl/ControlDemo/)
* YearVisible, MonthVisible, DayVisible, MinYear, MaxYear, Date, CalendarIdentifier - 详见下面示例代码中的注释
*/ using System;
using Windows.Globalization;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; namespace Windows10.Controls.DateControl
{
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 控件使用的日历系统,一个字符串值,在 CalendarIdentifiers 类中有封装
datePicker.CalendarIdentifier = CalendarIdentifiers.Gregorian;
} // DatePicker 控件选中的日期发生变化时触发的事件
private void datePicker_DateChanged(object sender, DatePickerValueChangedEventArgs e)
{
// e.OldDate - 原日期
// e.NewDate - 新日期
lblMsg.Text = $"OldDate - {e.OldDate.ToString("yyyy-MM-dd hh:mm:ss")}, NewDate - {e.NewDate.ToString("yyyy-MM-dd hh:mm:ss")}";
}
}
}
3、TimePicker 的示例
Controls/DateControl/TimePickerDemo.xaml
<Page
x:Class="Windows10.Controls.DateControl.TimePickerDemo"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows10.Controls.DateControl"
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="10 0 10 10"> <TextBlock Name="lblMsg" Margin="5" /> <!--
TimePicker - 时间选择控件
Header - 可以设置一个纯文本,不能命中测试,空 Header 的话不会占用任何空间
HeaderTemplate - 可以将 Header 设置为任何 xaml,且支持命中测试
TimeChanged - 选中的时间发生变化时触发的事件
-->
<TimePicker Name="timePicker1" Header="Time" TimeChanged="timePicker1_TimeChanged" Margin="5" /> <TimePicker Name="timePicker2" Header="Time" Margin="5" /> </StackPanel>
</Grid>
</Page>
Controls/DateControl/TimePickerDemo.xaml.cs
/*
* TimePicker - 时间选择控件(继承自 Control, 请参见 /Controls/BaseControl/ControlDemo/)
* Time, MinuteIncrement, ClockIdentifier - 详见下面示例代码中的注释
*/ using System;
using Windows.Globalization;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; namespace Windows10.Controls.DateControl
{
public sealed partial class TimePickerDemo : Page
{
public TimePickerDemo()
{
this.InitializeComponent(); this.Loaded += TimePickerDemo_Loaded;
} void TimePickerDemo_Loaded(object sender, RoutedEventArgs e)
{
// Time - TimePicker 控件当前显示的时间
timePicker1.Time = new TimeSpan(, , ); // MinuteIncrement - 分钟选择框的分钟增量(0, 15, 30, 45)
timePicker1.MinuteIncrement = ; // ClockIdentifier - 小时制式,ClockIdentifiers.TwelveHour(12HourClock),12 小时制
timePicker1.ClockIdentifier = ClockIdentifiers.TwelveHour; // ClockIdentifier - 小时制式,ClockIdentifiers.TwentyFourHour(24HourClock),24 小时制
timePicker2.ClockIdentifier = ClockIdentifiers.TwentyFourHour;
} // TimePicker 控件选中的时间发生变化时触发的事件
private void timePicker1_TimeChanged(object sender, TimePickerValueChangedEventArgs e)
{
// e.OldTime - 原时间
// e.NewTime - 新时间
lblMsg.Text = $"OldTime - {e.OldTime.ToString("c")}, NewTime - {e.NewTime.ToString("c")}";
}
}
}
OK
[源码下载]
背水一战 Windows 10 (44) - 控件(日期类): CalendarView, DatePicker, TimePicker的更多相关文章
- 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog
[源码下载] 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog 作者:webabcd 介绍背水一战 Windows 10 之 控 ...
- 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu
[源码下载] 背水一战 Windows 10 (36) - 控件(弹出类): ToolTip, Popup, PopupMenu 作者:webabcd 介绍背水一战 Windows 10 之 控件(弹 ...
- 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout
[源码下载] 背水一战 Windows 10 (35) - 控件(弹出类): FlyoutBase, Flyout, MenuFlyout 作者:webabcd 介绍背水一战 Windows 10 之 ...
- 背水一战 Windows 10 (34) - 控件(进度类): RangeBase, Slider, ProgressBar, ProgressRing
[源码下载] 背水一战 Windows 10 (34) - 控件(进度类): RangeBase, Slider, ProgressBar, ProgressRing 作者:webabcd 介绍背水一 ...
- 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch
[源码下载] 背水一战 Windows 10 (33) - 控件(选择类): ListBox, RadioButton, CheckBox, ToggleSwitch 作者:webabcd 介绍背水一 ...
- 背水一战 Windows 10 (32) - 控件(选择类): Selector, ComboBox
[源码下载] 背水一战 Windows 10 (32) - 控件(选择类): Selector, ComboBox 作者:webabcd 介绍背水一战 Windows 10 之 控件(选择类) Sel ...
- 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButton, AppBarButton, AppBarToggleButton
[源码下载] 背水一战 Windows 10 (31) - 控件(按钮类): ButtonBase, Button, HyperlinkButton, RepeatButton, ToggleButt ...
- 背水一战 Windows 10 (30) - 控件(文本类): AutoSuggestBox
[源码下载] 背水一战 Windows 10 (30) - 控件(文本类): AutoSuggestBox 作者:webabcd 介绍背水一战 Windows 10 之 控件(文本类) AutoSug ...
- 背水一战 Windows 10 (29) - 控件(文本类): RichTextBlock, RichTextBlockOverflow, RichEditBox
[源码下载] 背水一战 Windows 10 (29) - 控件(文本类): RichTextBlock, RichTextBlockOverflow, RichEditBox 作者:webabcd ...
随机推荐
- jvm相关知识点
1.hotspot虚拟机结构:类加载器.堆.栈.方法区.垃圾回收系统.执行引擎.本地方法栈.pc寄存器. 类加载器:负责将class文件从文件系统加载到方法区. 堆:存放对象的一块区域,所有线程共用. ...
- 【NIFI】 开发自定义Nifi Processor
本例需要基础知识:[NIFI] Apache NiFI 安装及简单的使用 Nifi不光可以使用自带的Processor,还可以自定义Processor.本例简单介绍开发一个Processor 开发 1 ...
- hdu--6178(多校
题意:要在一棵 n 个点的树上放 k 只猴子,然后删掉尽量多的边,使得删边后,每只猴子都至少和另外一只猴子相连,问最后剩下的边数. 思路:其实dfs遍历一次看有多少个点-边-点就好了,比赛的时候就觉得 ...
- hadoop报错:java.io.IOException(java.net.ConnectException: Call From xxx/xxx to xxx:10020 failed on connection exception: java.net.ConnectException: 拒绝连接
任务一直报错 现象比较奇怪,部分任务可以正常跑,部分问题报错 报错信息如下: Ended Job = job_1527476268558_132947 with exception 'java.io. ...
- vsftpd只能连接不能上传文件问题
Centos7 记得很清楚,vsftpd安装后,不需要配置,本地用户就可以正常使用(登录.上传.下载) 这次配的就是不行,另起了个虚拟机,装了下,就是不需要配置,但是在一台机上,就是不行,只能登录,下 ...
- 如何将字符串转化为Jsoup的Document 对象
有些时候在java操作解析html元素的时候比较繁琐,今天螃蟹就介绍一种可将html转换为document对象的方法——jsoup jsoup为我们解析html提供了比较全的API接口,我们通过将ht ...
- MySql常用命令集
MySql 常用命令集 Mysql常用命令 show databases; 显示数据库 create database name; 创建数据库 use databasename; 选择数据库 drop ...
- s4-6 二层交换
为什么需要二层交换? 有很多LAN,如何将它们连接起来? 可用网桥(bridges )将它们连接起来. 网桥工作在DLL层,通过检查MAC地址做出转发帧的决策 不会检查网络层,所以,IPv ...
- c# 抽象类和抽象方法
参考:http://www.runoob.com/csharp/csharp-polymorphism.html https://zhidao.baidu.com/question/587686949 ...
- js 匿名函数 用法
JS执行顺序为从上到下 先声明存储匿名函数的变量放在JS文件中 <script src="/Scripts/niming.js" type="text/javasc ...