3,038 questions
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