WP8.1 Pivot control's SelectedIndex property vs. Sunday bug

Source: Internet
Author: User

The pivot control has a selectedindex that can specify the currently displayed pivot Item;

I am in an application in the Monday to Sunday, altogether corresponds to seven pivot Item, and want to implement an open app to display the current date corresponding to the week page so write: SelectedIndex = (int) DateTime.Today.DayOfWeek;

The result is not the day's page, but the next day's page.

So I write the above code as SelectedIndex = ((int) datetime.today.dayofweek-1);

So after a few days, debugging up no problem.

Until today, this application in the black screen; I thought it was a problem with the code I added today, so I commented out the code we added today, and the result is a black screen.

has been tossing fast for one hours, breakpoints, debugging, or not resolved.

When I see SelectedIndex = ((int) datetime.today.dayofweek-1), this line of code suddenly realizes that the week is starting from Sunday;

Immediately checked, the original (int) DateTime.Today.DayOfWeek returned the integer is {0,1,2,3,4,5,6,}; corresponding {Sunday, Monday, ..., Friday, Saturday};

Pivot Item is also counted starting from 0, so the corresponding selectedindex in Sunday should be 6, and now the result is-1, no wonder it crashes.

And today happens to be Sunday!!! So I wasted almost one hours ...

Change to write this:

if ((int) datetime.today.dayofweek!=0)            {               Myclass.selectedindex = ((int) datetime.today.dayofweek-1);            }            else            {                myclass.selectedindex = 6;            }

Problem solving.

Summary: When writing code, be sure to think more in advance, pay attention to the corresponding counting starting point, in order to reduce the bug (especially this Sunday bug!), improve efficiency.

WP8.1 Pivot control's SelectedIndex property vs. Sunday bug

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.