Calendar SelectedDates quirk?

Jun 29, 2009 at 9:27 PM

Hi Y'All ;-)

I am setting a set of selected dates for the Calendar control using the SelectedDates.Add() method after calling SelectedDates.Clear() on the previous selected dates where the new range of dates is smaller than the previous one. Strangely, the previous range of dates remains in effect on the calendar display! For example, if the previous date range was June 12, 2009 to June 22, 2009 and the new range is June 15, 2009 to June 18, 2009, the range still reflects the larger span! Am I missing something here?


Jun 30, 2009 at 8:46 PM

Hi Hanoverian,

Are you adding individual DateTimes or DateTimeRanges? When you say "remains in effect on the calendar display" - do you mean that the Calendar UI still shows the cleared dates as selected? I was unable to reproduce your issue with individual DateTimes or DateTimeRanges. Can you provide a repro if your issue?


Eric, MSFT

Jul 4, 2009 at 6:42 PM

Hi Eric,

Thanks for getting back to me! The following code snippet displays the problem on my computer (Vista-64 SP1). Essentially, the problem is as follows: 1) there is a set of selected dates that come from an XML data set that say has only one date July 4, 2009 2) with the CheckBox below unselected, the user manually selects the following date range on the calendar control July 1, 2009 to July 7, 2009 3) the user checks the CheckBox to show only the date from the XML data set. As the code shows, the calendar SelectedDates are cleared and the single date is added to the calendar SelectedDates collection. The result is that the calendar control does not clear the previous date range! It appears that the Clear() method does not force a redraw of the control. Am I missing something?






        private void chkAllDates_Checked(object sender, RoutedEventArgs e)
            CheckBox cb = e.OriginalSource as CheckBox;
            if (cb != null)
                calendar.IsEnabled = (bool)!cb.IsChecked;

                // Show all dates from target file.
                foreach (DateTime dt in RecordDates)


Jul 21, 2009 at 3:30 AM

Hi Hanoverian -

I was able to reproduce your issue and a bug has been filed in our database. I have devised a temporary work-around for you. It may not be the best or the most appropriate, but it should work for your scenario. I highly suggest that you thoroughly test it as it is not guarenteed at all. With that said, you'll have to modify the source code in SelectedDatesCollection.cs, in the ClearItems() function, add the following line after this._owner.SelectedDate = null :   this._owner.HoverStart = null;

Let me know if it works out for you :-)

-Eric, MSFT