如何检查所选日期是否包含来自日历的日期小于今天的日期
how to check whether selected dates contains from calendar contains date less than todays date
我需要检查日历控件中的选定日期(多个)是否包含已经过去或小于今天的任何单个日期。
在 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); }
您可以按照此 link 获取 WPF 日历教程
http://www.c-sharpcorner.com/UploadFile/mahesh/wpf-calendar-control/
我需要检查日历控件中的选定日期(多个)是否包含已经过去或小于今天的任何单个日期。 在 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); }
您可以按照此 link 获取 WPF 日历教程
http://www.c-sharpcorner.com/UploadFile/mahesh/wpf-calendar-control/