Universal Windows apps, CalendarView

Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,866 Reputation points
2019-12-12T12:17:14.963+00:00

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

Universal Windows Platform (UWP)
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,866 Reputation points
    2019-12-12T12:18:46.877+00:00

    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

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.