我正在做一个小表格,想将我的日历设置为自动选择即将到来的星期日,我怎么能做到这一点?我有一种感觉,我必须做一些加载工作,但不确定是什么。
谢谢
最佳答案
你去...
使用此方法,您可以将日期设置为您决定的一周中的第二天,而不仅仅是周日,这使其变得更加灵活:
public static DateTime GetNextWeekday(DayOfWeek day)
{
DateTime start = DateTime.Today.AddDays(1);
int days = ((int)day - (int)start.DayOfWeek + 7) % 7;
return start.AddDays(days);
}
然后在您的PageLoad上:
DateTime nextSunday = GetNextWeekday(DayOfWeek.Sunday);
yourCalendarControl.SelectedDate = nextSunday;