WPF Calendar - Slow when connecting to a database

Jul 29, 2009 at 3:56 PM


I am using the Calendar control from the WPF toolkit, to display events based on values in an MS Access Table.

I customised the method decribed in the RedLetterDay example in this article, by placing my Select staement in the IValueConverter.
As a result, the performance is very slow, as it is making a seperate db connection for each day rendered in the calendar.

I takes approx 25 seconds to load, how can I reduce this time?

Is it possible to get the data once and then render the calendar?

If so, can someone show me how?



Jul 30, 2009 at 7:18 PM
Edited Jul 30, 2009 at 7:19 PM

Hi glyn123 -

Perhaps you can subscribe to DisplayDateChanged (which gets fired when the users navigates the control to a new mode, month, year, or decade). In your event handler you can run your query for the newly viewable month and pass those results to you converter that you added to the CalendarDayButtons. This should speed up your app and cut down on the number of queries that has to be executed.

In the event handler you may want to add some additional logic to avoid unecessary/redundant queries. This kind of situation can arise when a user changes the SelectedDate within a a month then changes the mode from Month to Year. Example logic:

if(!e.RemovedDate.Value.Month.Equals(e.AddedDate.Value.Month) || !e.RemovedDate.Value.Year.Equals(e.AddedDate.Value.Year) ) {

//e is the CalendarDateChangedEventArgs in you event handler

//run query with e.AddedDate and pass results to the Converter


 Additionally, you *may* want to run your query on another thread or give it to the dispatcher to ensure that you aren't blocking the UI. This may help if you're unfamilair with these topics:


-Eric, MSFT