The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
Universal Windows apps, CalendarView RRS feed

  • Question

  • Is there any way to add weeknumbers to the left of the calendar
    Friday, November 15, 2019 10:43 AM

All replies

  • Hi

    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);
    }

    By the way, We invite you to post new questions in the "Developing Universal Windows apps" forum’s new home on Microsoft Q&A (Preview)!


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, November 15, 2019 1:33 PM