question

NicoZhu-MSFT avatar image
0 Votes"
NicoZhu-MSFT asked ·

Universal Windows apps, CalendarView

Is there any way to add weeknumbers to the left of the calendar?

uwpuwp-xaml
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

NicoZhu-MSFT avatar image
0 Votes"
NicoZhu-MSFT answered ·

Hello,

The default CalendarView does not contain weeknumbers property, For your requirement, you could calculate week number manually. You could use the following code to get weeknumbers with specific DateTime.

 public static int GetIso8601WeekOfYear(DateTime time)
 {
     DayOfWeek day = CultureInfo.InvariantCulture.Calendar.GetDayOfWeek(time);
     if (day >= DayOfWeek.Monday && day <= DayOfWeek.Wednesday)
     {
         time = time.AddDays(3);
     }
    
     // Return the week of our adjusted day
     return CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(time, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
 }

Call above method when you select the Date from CalendarView

 private void MyCalendarView_SelectedDatesChanged(CalendarView sender, CalendarViewSelectedDatesChangedEventArgs args)
 {
   var date =   args.AddedDates.First().DateTime;
   var numberOfWeek = GetIso8601WeekOfYear(date);
 }

Thanks,
Nico

· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.