private static void OnSelectedDateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Calendar c = d as Calendar;
Debug.Assert(c != null, "c should not be null!");
if (!c.IsHandlerSuspended(Calendar.SelectedDateProperty))
{
if (c.SelectionMode != CalendarSelectionMode.None)
{
DateTime? addedDate;
addedDate = (DateTime?) e.NewValue;
if (IsValidDateSelection(c, addedDate))
{
if (addedDate == null)
{
c.SelectedDates.Clear();
}
else
{
if (addedDate.HasValue && !(c.SelectedDates.Count > 0 && c.SelectedDates[0] == addedDate.Value))
{
foreach (DateTime item in c.SelectedDates)
{
c.RemovedItems.Add(item);
}
c.SelectedDates.ClearInternal();
// the value is added as a range so that the
// SelectedDatesChanged event can be thrown with
// all the removed items
c.SelectedDates.AddRange(addedDate.Value, addedDate.Value);
}
}
// We update the LastSelectedDate for only the Single
// mode. For the other modes it automatically gets
// updated when the HoverEnd is updated.
if (c.SelectionMode == CalendarSelectionMode.SingleDate)
{
c.LastSelectedDate = addedDate;
}
}
else
{
throw new ArgumentOutOfRangeException("d", WinRTXamlToolkit.Controls.Properties.Resources.Calendar_OnSelectedDateChanged_InvalidValue);
}
}
else
{
throw new InvalidOperationException(WinRTXamlToolkit.Controls.Properties.Resources.Calendar_OnSelectedDateChanged_InvalidOperation);
}
}
}
#endregion SelectedDate