private static void OnDataSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MonthCalendar mcc = (MonthCalendar)d;
// WeakEventManager is used here to avoid a potential memory leak
// Please see the comments in WeakEventManager/WeakEventManagerTemplate for more details
if (e.OldValue is INotifyCollectionChanged)
{
CollectionChangedEventManager.RemoveListener((INotifyCollectionChanged)e.OldValue, mcc);
}
if (e.NewValue is INotifyCollectionChanged)
{
CollectionChangedEventManager.AddListener((INotifyCollectionChanged)e.NewValue, mcc);
}
mcc.UpdateDataSource();
}