微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Silverlight Toolkit 中 DatePicker & TimePicker 的用法

 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");
        }

 

接口:

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。

如下图:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐