我需要检查日历控件中的选定日期(多个)是否包含已经过了或者比今天少的任何单个日期。 如何在c#wpf应用程序中实现。
答案 0 :(得分:1)
尝试以下代码
SelectedDatesCollection selectedDatesCollection = myCalendar.SelectedDates;
if (selectedDatesCollection.Count > 0)
{
if (selectedDatesCollection.Any(x => x < new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day)))
MessageBox.Show("passed or less than today");
else
MessageBox.Show("today or future date");
}
答案 1 :(得分:0)
private void CreateDynamicCalendar() {
Calendar MonthlyCalendar = new Calendar();
MonthlyCalendar.Name = "MonthlyCalendar";
MonthlyCalendar.Width = 300;
MonthlyCalendar.Height = 400;
MonthlyCalendar.Background = Brushes.LightBlue;
MonthlyCalendar.DisplayMode = CalendarMode.Month;
MonthlyCalendar.SelectionMode = CalendarSelectionMode.MultipleRange;
MonthlyCalendar.DisplayDateStart = new DateTime(2010, 3, 1);
MonthlyCalendar.DisplayDateEnd = new DateTime(2010, 3, 31);
MonthlyCalendar.SelectedDates.Add(new DateTime(2010, 3, 5));
MonthlyCalendar.SelectedDates.Add(new DateTime(2010, 3, 15));
MonthlyCalendar.SelectedDates.Add(new DateTime(2010, 3, 25)); /*You Can Check all selected dates here with respect to current date*/
MonthlyCalendar.FirstDayOfWeek = DayOfWeek.Monday;
MonthlyCalendar.IsTodayHighlighted = true;
LayoutRoot.Children.Add(MonthlyCalendar); }
您可以按照此链接获取WPF日历教程
http://www.c-sharpcorner.com/UploadFile/mahesh/wpf-calendar-control/