Workaround for Calendar control template bug?

Sep 3, 2009 at 2:58 PM

The control template for the Calendar control appears to have a bug, which I have reported on the Issue Tracker. Now I need to find a workaround.

The bug is simple to reproduce. In Blend, create a window and add a Calendar control to it. Next, create a copy of the Calendar control template by right-clicking the Calendar and selecting Edit Template > Edit a Copy from the context menu. A PART_CalendarItem will appear below the control in the Objects and Timeline window. Finally, create a copy of the PART_CalendarItem template by right-clicking it and again selecting Edit Template > Edit a Copy from the context menu.

At this point, you have a Calendar control styled to an unmodified Calendar control template. Hit F5 to run the project, and move the cursor over the month name or either navigation arrow. The project will crash, with the following error:

'TextColor' name cannot be found in the name scope of 'System.Windows.Controls.Grid'.

If you look at the XAML for the control template, you can see the problem. In the HeaderButtonTemplate section, around line 80, you will see the following:

<ColorAnimation Duration="00:00:00" Storyboard.TargetName="TextColor" Storyboard.TargetProperty="Color" To="#FF73A9D8"/>

The line is supposed to change the text color of the Month name when you mouse over it, to indicate that it is, in fact, a button. The problem appears to be that the TextColor assignment applies to the grid that contains the VisualStateManager, rather than the text for the HeaderButton. The same problem occurs in the templates for the Previous and Next buttons at the top of the calendar.

So, here's my question: How do I modify the Calendar control template to eliminate the problem? I know I can comment-out or remove the offending statements. But if I do, I lose the mouse-over effect on the calendar buttons, and I would really like to keep those. Can you suggest how to fix the problem, to the mouse-over effect works as it should? Thanks for your help.


Oct 2, 2009 at 6:00 AM

I know you were looking for help for this a month ago, but I wanted to post the explanation for posterity. I believe this is your StackOverflow question, I did my best to answer:

Oct 2, 2009 at 2:07 PM

Thanks--Accepted and upvoted on StackOverflow!