The date and time picker in Windows Phone 8.1 datepicker,timepicker

Source: Internet
Author: User

Before opening, recommend Mr. Wang Lei's explanation of DatePicker and Timepicker in Windows 8.1

Link: Re-imagine Windows 8.1 Store Apps (73)-New controls: DatePicker, Timepicker


First, the use of these two selectors for Windows Phone 8.1 is similar to that used in Windows 8.1.

1. The use of DatePicker and timepicker tags at the front desk is not much of a problem, with the header attribute actually giving the selector a name.

DateChanged and timechanged indicate events that are triggered when a date or time change is selected

2. For the date format problem, you can set the display format by Microsoft's own template (this has many combinations, on-demand writing, need to explore their own

Explore, best view MSDN documentation)

Links: Format Specification links

3. For the settings of the Orientation property, I do not see what the difference in WP, whether set to horizontal or vertical are as shown



4. In the background you can make additional settings and rules for the date and time selector to control its display and behavior

A. The date that the control is displayed by default is the date of the day, but we can control it to show the date we asked to display

The following datepicker,datepicker1,datepicker3 is the X:name property value of the foreground DatePicker selector

Method One: Datepicker1.date = DatePicker1.Date.AddYears (n);//control displays the year, n represents an integer, and the final year is displayed as

Plus n, positive numbers can be negative

For example, n=2, the current 2014+2=2016, show 2016, if N=-1, it is 2012

Similarly datepicker1.date = DatePicker1.Date.AddMonths (-2); and datepicker1.date = DatePicker1.Date.AddDays (3);, original

Same

Method Two: Datepicker1.date = DateTimeOffset.Now.AddYears (2); This is dependent on your machine time, that is, in your computer

The date is displayed on the basis of the time on the add minus operation

The recommended method is to use less, because once the two methods are mixed, sometimes the latter may have an effect on the former.

For example, previously set to:

Datepicker1.date = DatePicker1.Date.AddYears (2);

Datepicker1.date = DateTimeOffset.Now.AddMonths (2);

The year setting will take effect, and the current year will still be displayed without adding 2 to the current year. And the month can be normal plus 2 after the display


B. Control the setting for the maximum year and the minimum year of the date control, but the month and day do not have such a setting! as follows

Datepicker.minyear = DatePicker.Date.AddYears (-4); Controls the minimum allowable year for a control

Datepicker.maxyear = DatePicker.Date.AddYears (4); Maximum year allowed for control control

Or:

Datepicker.minyear = DateTimeOffset.Now.AddYears (-4); Controls the minimum allowable year for a control

Datepicker.maxyear = DateTimeOffset.Now.AddYears (4); Maximum year allowed for control control

The difference between the two methods can be, the second is dependent on the computer time to set. Intuitively, the effect is as follows:



C. Controls whether the Year,month,day selection box is displayed, which is true (shown) by default, as shown in the following scenario:

Datepicker.yearvisible = false;
Datepicker.monthvisible = true;
Datepicker.dayvisible = true;

You can see that the months and days left are optional. Three kinds of any combination!



D. Set the date control's calendar system, in order to effect a little, I set up the Japanese, because the Japanese are the Emperor era name.

Datepicker3.calendaridentifier = calendaridentifiers.japanese;//This is set as Japan calendar system




Then there's the code on the time selector, which has comments on it.

As long as the minute minimum component of the setting of the effect on the point of time can be, seemingly hours and seconds no minimum component of the setting!

If you control that the time displayed by the control is not an integer multiple of the minimum component of the minute selection box, the minute column is automatically adjusted from the setting value to the value nearest to the integer multiple of the minimum component value//control display time Timepicker.time = new TimeSpan (3,22,0); /control the Min component of the Control minute selection box Timepicker.minuteincrement = 3;//control whether the time selection control is a 12-hour or 24-hour system Timepicker.clockidentifier = clockidentifiers.twelvehour;//Select a 12-hour system or clockidentifiers.twentyfourhour set to 24-hour

More intuitive: Note that I set the 22 points, but because set the min component of the minute is 3, so the display when the actual display is 21 points

Note that this minute is a unit of 3 minutes:





5. Date, time change event triggered

private void Datepicker_datechanged (object sender, Datepickervaluechangedeventargs e) {     Txtmsg.text = e. Newdate.tostring ("Yyyy-mm-dd hh:mm:ss");} Format specification Link: http://msdn.microsoft.com/zh-cn/library/ee372286.aspxprivate void timepicker_timechanged (object sender, Timepickervaluechangedeventargs e) {     txtmsg1.text = e.newtime.tostring ("G");}


Think, if the current is December, use datepicker1.date = DatePicker1.Date.AddMonths (2), to control the control display month, then the control

Is the month shown in 2 or 14?

Obviously 14 is not conventional, if so, how to do it, programming or to keep moving the brain, the problem to a large number to practice to answer.


The above is some of my understanding and sentiment, not necessarily all is right, we learn from each other.



Date and time picker datepicker,timepicker

in Windows Phone 8.1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.