如何检查所选日期是否包含 日历包含小于今天的日期

本文关键字:日期 包含 是否 日历 小于 今天 何检查 检查 | 更新日期: 2023-09-27 18:30:52

我需要检查日历控件中的选定日期(多个)是否包含任何已经通过或小于今天的单个日期。在 c# wpf 应用程序中怎么可能。

如何检查所选日期是否包含 日历包含小于今天的日期

尝试下面的代码

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