views:

148

answers:

2

Is there a simple way to change the text color of a WPF Toolkit Calendar control? I thought it would be simple, but it appears that the color is hard-coded. To change it, I am going to have to go pretty deep into the control templates for the Calendar and its component parts.

Doing so has some undesirable side effects. Here is an example: I copied the control template for the Calendar control and its component parts (CalendarItem, CalendarButton, CalendarDayButton) to a local resource dictionary, then set the styles for my instance of the Calendar to the local resources, like this:

<toolkit:Calendar  
    Name="calendar1" 
    Style="{StaticResource Outlook2010CalendarStyle}" 
    CalendarItemStyle="{StaticResource Outlook2010CalendarItemStyle}"
    CalendarButtonStyle="{StaticResource Outlook2010CalendarButtonStyle}"
    CalendarDayButtonStyle="{StaticResource Outlook2010CalendarDayButtonStyle}"  />

Unfortunately, when I set the CalendarDayButtonStyle, I lost the "grayed out" effect that the control normally applies to days before the beginning and after the end of the month. So, it looks like I am going to have to restore that effect in my own markup or code.

Before I go any deeper down the rabbit-hole, I thought I would stop and do a reality check. Do I really need to do all this, just to change the color of the text on the Calendar control? Is there a simpler approach that I am missing? Has anyone derived a custom control that allows for a simple change of the text color? Thanks for your help.

A: 

Apparently, there is no easy way to do this. I had to dig pretty deeply into the control template--the calendar text color was hard-coded at a number of different points, and not linked to a style.

The text color markup uses named SolidColorBrush objects, which can't simply be replaced by resource references. You have to break the color property out as a separate tag and use a reference to a color resource.

David Veeneman
A: 

This isn't an answer but I have the same problem. Oddly I can style the CalendarButton okay (the one for the months and years in the grid), but when you style the CalendarDayButton, you lose the grey days that aren't in the month, the highlight color, etc.

The Calendar, Datepicker and Datagrid from the WPFToolkit all seem very substandard and flaky.

dex3703