"Miles Journey--windows app development" Datepicker&timepicker

Source: Internet
Author: User

In the front we have introduced a lot of controls, which naturally include this datepicker and Timepicker, then a little more advanced usage?

If you want to make an app about fitness, alarms, and so on, it's inevitable that you'll have time to use these controls.

<DatePicker x:name="DatePicker" Header="nomasp Date"  Foreground="Beige"/>          <button x:name="Btnok" click ="Btnok_click" Content= "OK" Foreground= "Cyan" Margin= "292,378,0,352 ">     <button.flyout>          <flyout>              <TextBlock x:name="Tblock1" Foreground="fuchsia"/>          </flyout>     </button.flyout></Button>

Then we may need to select the time to be the next time, that is, more time than the application runtime. Getting the currently selected time to use in other parts of the program is also very simple, and my year here has been defined before, oh, it's unwise to define within a function.

        Privatevoid Btnok_click (object sender, RoutedEventArgs e) {if(DatePicker.Date>datetimeoffset. Now) {Tblock1. Text =string. Format ("The time you selected is: {0}." ", DatePicker.Date. ToString ("D")); }Else{Tblock1. Text ="Oh! Do you want to cross it? "; } Year= DatePicker.Date. Year;Month= DatePicker.Date.Month; Day= DatePicker.Date. Day; }

The interesting thing comes again, if you want to make a time capsule, the default time is 10 years later, then the initial event of DatePicker is not very good if it happens to be 10 years later. So what we're going to do, first of all, is to write an event for DatePicker's loaded. (Haha, I think the app is not saved for 10 years yo)

privatevoiddatePicker_Loaded(object sender, RoutedEventArgs e){    datePicker.Date = DateTimeOffset.Now.AddYears(10);}

If you do not want to selectmen to use the DatePicker loaded, then you can also directly in the background code to write Oh.

protectedoverridevoidOnNavigatedTo(NavigationEventArgs e){    datePicker.Date = DateTimeOffset.Now.AddYears(10);}

I also made a small test, in the loaded event to increase the time of 11, in the Onnavigatedto event to increase the time of 10, the result-the result is increased by 11 years, it seems that their own loaded more powerful.

Next is Timepicker, back to the fitness topic, assuming that Kazakhstan, 6 to 18 o'clock is not suitable for sports, then our Microsoft Band made the following request (joking).

    Private void Btnok_click(Objectsender, RoutedEventArgs e) {TimeSpan startTime =NewTimeSpan (6,0,0); TimeSpan EndTime =NewTimeSpan ( -,0,0);if(Timepicker.time>=starttime&&timepicker.time<=endtime) {Tblock1. Text =string. Format ("This is a good time to exercise, oh--{0}." ", timePicker.Time.ToString ()); }Else{Tblock1. Text ="This time is not suitable for sports, right?" "; }               }

Maybe you want to control the initial time of the time picker on the bracelet, then the code comes.

protectedoverridevoidOnNavigatedTo(NavigationEventArgs e){                                                   new TimeSpan(2300);}

As an obsessive-compulsive disorder, every time I set an alarm, I set it to a better time, such as being divisible by 5 and prime numbers. Here you can use the Minuteincrement property to control the increment of the minute, such as the increment of 5. From elementary school to fly to the electronic watch time to set to 24-hour system, this is also achievable, Clockidentifier set to 24HourClock is done.

This blog is relatively simple, so there is no map, in addition to help use the traffic to read the previous blog and then look at this article of the children's shoes province point of flow. So, next goodbye, feel everyone's support!

"Miles Journey--windows app development" Datepicker&timepicker

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.