David Veeneman
David Veeneman

Reputation: 19122

Changing text color on a WPF Calendar?

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 ControlTemplate 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.

Upvotes: 2

Views: 2353

Answers (2)

Shai UI
Shai UI

Reputation: 51918

Not sure how you can do this in Visual Studio / Code, but using Expression Blend it's fairly easy. Just right click the Calendar that you've dragged to your designer, hit "edit additional templates", pick Edit CalendarDayButtonStyle, this will extract the template out for you in xaml, now you can customize it any way you want.

Upvotes: 2

David Veeneman
David Veeneman

Reputation: 19122

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.

Upvotes: 0

Related Questions