More Changes to Calendar Control for WP 7

In the spirit of further improving my calendar control for Windows Phone 7, I added ability to show week number in the first column of the calendar control.

image

As you can see, the very first column can show week number,.  If course, I cannot break existing functionality, so the feature is disabled by default.  You can enable it by setting appropriate property on calendar control, called WeekNumberDisplay.  It has three options:


namespace WPControls
{
 
   
/// <summary>

   
/// Option of how to display week numbers in the calendar
   
/// </summary>
   
public enum WeekNumberDisplayOption
    {
       
/// <summary>
       
/// Do not show week number
       
/// </summary>
        None = 0,
       
/// <summary>
       
/// Show week number starting with start of the year
       
/// </summary>
        WeekOfYear = 1,
       
/// <summary>
       
/// Show week number starting with start of month
       
/// </summary>

        WeekOfMonth = 2
    }
}

 

So, you have options to show week of the year, week of the month or none.  Week of the month is simply number that starts with 1.  As far as week of the year goes, I am using built in functionality to properly determine this using localization rules as follows.

var systemCalendar = System.Threading.Thread.CurrentThread.CurrentCulture.Calendar;
weekNumber = systemCalendar.GetWeekOfYear(
  item.ItemDate,
  System.Threading.
Thread
.CurrentThread.CurrentCulture.DateTimeFormat.CalendarWeekRule,
  System.Threading.
Thread
.CurrentThread.CurrentCulture.DateTimeFormat.FirstDayOfWeek);

 

You can use this code any time you need to determine week number.

You can visit the home page for calendar control to download the latest source code.

http://wpcontrols.codeplex.com/

Thank you and keep the suggestions coming.

Leave a Reply

Your email address will not be published. Required fields are marked *