R – Animating a custom Button ControlTemplate Foreground

netsilverlightsilverlight-2-rc0

I want to change/animate the Foreground property of a custom button control template depending on the control's state.

Pre-RC0, I set the Foreground of the ContentPresenter, gave it an x:Name, and referenced it in the VisualStateManager transitions.

Now, ContentPresenter no longer has a Foreground, since it doesn't inherit from Control anymore. Usually, I would set the Foreground in the Style which is applied to the templated control. But I cannot reference that from the VisualStateManager transitions / states. I also cannot wrap it in a TextBlock which has the Foreground property set, and (edit:) Border has no Foreground property.

Help is greatly appreciated.

Update:

I can solve the problem for some of the removed properties with a Border, but not those relating to font/text, including Foreground.

Since it doesn't seem possible, in my particular case I was able to replace the ContentPresenter with a TextBlock.

Best Answer

There is a post from Jesse Liberty dealing with this issue. In a few words, the idea is that you can't, because you would be forcing any content in the button to have a specific foreground colour, and that decision should be left to the content itself.

Anyway, perhaps you may want to take a look at the concept of hijacking dependency properties, which is using another property of the same type for what you want. It isn't a nice practice, but will certainly work.