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