C# 如何检查所选日期是否包含“从日历”中包含的日期小于“今天”日期

C# 如何检查所选日期是否包含“从日历”中包含的日期小于“今天”日期,c#,wpf,date,calendar,C#,Wpf,Date,Calendar,我需要检查从日历控件中选择的日期(多个)是否包含任何已过的日期或小于今天的日期。 如何在c#wpf应用程序中实现这一点。请尝试下面的代码 SelectedDatesCollection selectedDatesCollection = myCalendar.SelectedDates; if (selectedDatesCollection.Count > 0) { if (selectedDatesCollection.Any(x => x < new DateT

我需要检查从日历控件中选择的日期(多个)是否包含任何已过的日期或小于今天的日期。 如何在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");
}
SelectedDatesCollection SelectedDatesCollection=myCalendar.SelectedDates;
如果(selectedDatesCollection.Count>0)
{
if(selectedDatesCollection.Any(x=>x<新日期时间(DateTime.Now.Year,DateTime.Now.Month,DateTime.Now.Day)))
MessageBox.Show(“通过或少于今天”);
其他的
MessageBox.Show(“今天或未来日期”);
}
您可以通过此链接获得WPF日历教程


mvvm环境还是简单环境?能否显示如何存储日历控件中选定日期的代码?我正在使用鼠标在UI中一次从日历中选择多个日期。所以我需要得到所有的日期,并将每个日期与今天的日期进行比较。我使用的是简单环境哇。。。太棒了。简简单单。
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);  }