private static void OnVisibleMonthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MonthCalendar mcc = (MonthCalendar)d;
DateTime oldDate = (DateTime)e.OldValue;
DateTime newDate = (DateTime)e.NewValue;
//oldDate != newDate in Year/Month field
if (MonthCalendarHelper.CompareYearMonth(oldDate, newDate) != 0)
{
try
{
//raise the event
mcc.OnVisibleMonthChanged(new RoutedPropertyChangedEventArgs<DateTime>(oldDate, newDate, VisibleMonthChangedEvent));
}
finally
{
mcc.SetFlag(Flags.IsSwitchingMonth, true);
try
{
mcc.InvalidateVisibleDays(MonthCalendarHelper.SubtractByMonth(newDate, oldDate));
}
finally
{
mcc.SetFlag(Flags.IsSwitchingMonth, false);
}
}
}
}