Color some dates in the toolkit Calendar control.

Mar 31, 2009 at 6:46 PM

I want to color some dates in the Calendar control based on a runtime value. Using the style template doesn't quite do it it seems. What I need is programmatic
access to the individual CalendarDayButton controls in the Calendar control. I can get at the CalendarItem in the Calendar using code like this:

using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using System.Windows.Shapes;

namespace Foo
    public class CalendarEx : Calendar
        public override void OnApplyTemplate()

            CalendarItem item = this.GetTemplateChild("CalendarItem") as CalendarItem;
            item.Background = new SolidColorBrush(Colors.Brown);

This sets the background color of the control to brown. I cannot do the same with the CalendarDayButton as that class, and the CalendarItem class are sealed.
Also, setting the template doesn't give me access to each individual button. Is there a solution to my problem other than rewriting a Calendar control from scratch?


Mar 31, 2009 at 7:02 PM
It seems I didn't search hard enough. Found a clue here:

I'll take alook at that.