private static void OnDisplayDateStartChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Calendar c = d as Calendar;
Debug.Assert(c != null, "c should not be null!");
if (!c.IsHandlerSuspended(Calendar.DisplayDateStartProperty))
{
DateTime? newValue = e.NewValue as DateTime?;
if (newValue.HasValue)
{
// DisplayDateStart coerces to the value of the
// SelectedDateMin if SelectedDateMin < DisplayDateStart
DateTime? selectedDateMin = SelectedDateMin(c);
if (selectedDateMin.HasValue && DateTime.Compare(selectedDateMin.Value, newValue.Value) < 0)
{
c.DisplayDateStart = selectedDateMin.Value;
return;
}
// if DisplayDateStart > DisplayDateEnd,
// DisplayDateEnd = DisplayDateStart
if (DateTime.Compare(newValue.Value, c.DisplayDateRangeEnd) > 0)
{
c.DisplayDateEnd = c.DisplayDateStart;
}
// If DisplayDate < DisplayDateStart,
// DisplayDate = DisplayDateStart
if (DateTimeHelper.CompareYearMonth(newValue.Value, c.DisplayDateInternal) > 0)
{
c.DisplayDate = newValue.Value;
}
}
c.UpdateMonths();
}
}