Silverlight Toolkit 中 DatePicker & TimePicker 的用法
2011-09-01 15:50
489 查看
Toolkit的下载安装以及VS工程中的引用的加入在之前的文章已经提到。这里就不再多说。
直接切入主题,看一下这两个控件。
DatePicker,就是关于日期(比如:2011/09/01)操作的控件;
TimePicker,很明显它是关于时间操作的控件。
下面主要介绍它们的一些特殊属性和事件。
属性:
PickerPageUri,可以点击该控件进行页面的跳转,当然这个属性的值就是要跳转到的页面
比如:
PickerPageUri="/DatePickerDemo;component/CustomPage.xaml"
跳转到DatePickerDemo目录下的CustomPage.xaml对应的界面
ValueStringFormat,两控件的值的一个具体格式
DatePicker控件这个属性的设置:
ValueStringFormat="{}{0:d}" 模拟器上显示:9/1/2011
ValueStringFormat="{}{0:MMMM dd}" September 01
TimePicker控件这个属性的设置:
ValueStringFormat="{}{0:t}" 时:分 AM/PM
ValueStringFormat="{}{0:T}" 时:分:秒 AM/PM
应该还有一些其它的格式,但是lz没有找到。
ValueString,保存了当前控件的值
比如:this.textBlock.Text = datePicker.ValueString;
Value, 可以给控件赋初值
比如:Value="08:08:08"
事件:
ValueChanged,当前控件的值发生变化时,响应此事件。
this.datePicker1.ValueChanged += new EventHandler<DateTimeValueChangedEventArgs>(datePicker1_ValueChanged);
void datePicker1_ValueChanged(object sender, DateTimeValueChangedEventArgs e)
{
DateTime date = (DateTime)e.NewDateTime;
this.textBlock2.Text = date.ToString("d");
}
接口:
查看接口的源码,很简单:
// Summary:
// Represents an interface for DatePicker/TimePicker to use for communicating
// with a picker page.
public interface IDateTimePickerPage
{
// Summary:
// Gets or sets the DateTime to show in the picker page and to set when the
// user makes a selection.
DateTime? Value { get; set; }
}
具体的使用例子,感兴趣的可以看看这个链接http://windowsphonegeek.com/articles/wp7-datepicker-and-timepicker-in-depth--api-and-customization
控件背景的修改:
<toolkit:DatePicker.Background>
<ImageBrush ImageSource="bk.jpg"/>
</toolkit:DatePicker.Background>
在这里,在工程中添加了该图片后,会提示有错误:
The file 'bk.png' is not part of the project or its 'Build Action' is not set to "Resource"
首先确认一下有没有它提示的问题,如果没有重新编译一下就OK。
如下图:
直接切入主题,看一下这两个控件。
DatePicker,就是关于日期(比如:2011/09/01)操作的控件;
TimePicker,很明显它是关于时间操作的控件。
下面主要介绍它们的一些特殊属性和事件。
属性:
PickerPageUri,可以点击该控件进行页面的跳转,当然这个属性的值就是要跳转到的页面
比如:
PickerPageUri="/DatePickerDemo;component/CustomPage.xaml"
跳转到DatePickerDemo目录下的CustomPage.xaml对应的界面
ValueStringFormat,两控件的值的一个具体格式
DatePicker控件这个属性的设置:
ValueStringFormat="{}{0:d}" 模拟器上显示:9/1/2011
ValueStringFormat="{}{0:MMMM dd}" September 01
TimePicker控件这个属性的设置:
ValueStringFormat="{}{0:t}" 时:分 AM/PM
ValueStringFormat="{}{0:T}" 时:分:秒 AM/PM
应该还有一些其它的格式,但是lz没有找到。
ValueString,保存了当前控件的值
比如:this.textBlock.Text = datePicker.ValueString;
Value, 可以给控件赋初值
比如:Value="08:08:08"
事件:
ValueChanged,当前控件的值发生变化时,响应此事件。
this.datePicker1.ValueChanged += new EventHandler<DateTimeValueChangedEventArgs>(datePicker1_ValueChanged);
void datePicker1_ValueChanged(object sender, DateTimeValueChangedEventArgs e)
{
DateTime date = (DateTime)e.NewDateTime;
this.textBlock2.Text = date.ToString("d");
}
接口:
IDateTimePickerPage, 需要包含命名空间:using Microsoft.Phone.Controls.Primitives;
查看接口的源码,很简单:
// Summary:
// Represents an interface for DatePicker/TimePicker to use for communicating
// with a picker page.
public interface IDateTimePickerPage
{
// Summary:
// Gets or sets the DateTime to show in the picker page and to set when the
// user makes a selection.
DateTime? Value { get; set; }
}
具体的使用例子,感兴趣的可以看看这个链接http://windowsphonegeek.com/articles/wp7-datepicker-and-timepicker-in-depth--api-and-customization
控件背景的修改:
<toolkit:DatePicker.Background>
<ImageBrush ImageSource="bk.jpg"/>
</toolkit:DatePicker.Background>
在这里,在工程中添加了该图片后,会提示有错误:
The file 'bk.png' is not part of the project or its 'Build Action' is not set to "Resource"
首先确认一下有没有它提示的问题,如果没有重新编译一下就OK。
如下图:
相关文章推荐
- 时间对话框。。。datePickerDialog&timePickerDialog
- android datepicker timepicker简单用法
- wp7中设置toolkit的工具栏图标不能正常显示(DatePicker和TimePicker)
- DatePicker&TimePicker
- DatePicker && TimePicker 【Android】
- Android学习笔记之——DatePicker&TimePicker
- 【原创】Micrsoft Date and Time Picker Control (也就是MsCOMMCT2.OCX)控件在VC中不显示的问题及VC自带的Date Time Picker的用法
- android中提示&对话框----ProgressDialog&DatePickerDialog &TimePickerDialog&PopupWindow
- Android开发之DatePickerDialog与TimePickerDialog的功能和用法详解
- android *** TimePickerDialog && DatePickerDialog
- DatePicker&&TimePicker In DialogFragment
- Picker(Time picker&& Date picker)
- A07_TimePicker & DatePicker & AnalogClock & DigitalClock 的设置小结
- 遇见,控件----Datepicker&TimePicker
- TimePickerDialog、TimePicker、DatePickerDialog、DatePicker用法
- 喝酒不骑马的Android自学日记(7)-ListView监听器&&Date/TimePicker介绍
- WPFToolkit Calendar & DatePicker 使用介绍
- JQuery datepicker 用法
- 安装Microsoft Date and Time Picker Control 6.0(SP4)控件
- 日期 bootsrtap-datatimepicker and bootstrap-datepicker 控件支持中文