2016-01-19 152 views
-1

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

+0

MVVM环境或简单的环境? –

+0

你可以显示你的代码是如何存储日历控件中的选定日期的吗? –

+0

我在用户界面中使用鼠标从日历中选择多个日期。所以我需要得到所有的日期和比较每一个日期与今天的日期。 – Dipak

回答

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

哇...它真棒。简单。 – Dipak

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/

相关问题