locked
TextBlock in a ButtonTemplate doesn't show RRS feed

  • Question

  • I was trying to animate a content presenter in a button's template and failed due to an error.  I changed the <ContentPresenter/> to <TextBlock/> and suddenly the Button template's content stopped from displaying - can anyone tell me what is wrong ?

    Thursday, May 15, 2008 4:32 PM

Answers

  • Oh yes. This is a restriction in Beta1. Currently animations on custom DependencyProperty are not allowed. By custom DependencyProperty, I mean those DPs not defined in System.Windows.dll assembly. In Beta1, ContentPresenter is in System.Windows.Controls.dll, and thus its Foreground property is considered as a custom DP. In Beta2, System.Windows.Controls.dll will be merged to System.Windows.dll. Also the restriction of animation on custom DP is likely to be removed. I can't 100% assure you this feature at this time though...

     

    Monday, May 19, 2008 11:15 PM

All replies

  • Do you have some text in the TextBlock element? If you do, you should see that text. But then the text displayed will be the same hard coded text irrespective of the content you assign to the Button. But the reason we add a ContentPresenter to the template of a ContentControl is so that what is assigned to the content property of the Button is displayed at the position occupied by the ContentPresenter.

    Hope this helps,
    Jim (http://jimmangaly.blogspot.com/)

    Please MARK the replies as answers if they answered your question

    Thursday, May 15, 2008 4:58 PM
  •  There is text assigned to the TextBlock.Text via {TemplateBinding Content} I'm going to try hard coding it just to make sure. I'd use the ContentPresenter but I can't animate the text's foreground color

    Thursday, May 15, 2008 5:34 PM
  • Hello, Button.Content is of type object, not string. A Button's Content can be anything, not just text. So you need a ContentPresenter to display the Content. ContentPresenter also has a Foreground property. So what's the problem with your animation on foreground color?

    Monday, May 19, 2008 2:54 AM
  • Here's how to reproduce the problem :

     

    Create a simple button template, using Blend 2.5 march preview, attempt to record an animation which changes the foreground color. Blend will either throw an exception, crash or do both. That's what's happening to me 100% of the time lol. 

    Monday, May 19, 2008 8:05 AM
  • Oh yes. This is a restriction in Beta1. Currently animations on custom DependencyProperty are not allowed. By custom DependencyProperty, I mean those DPs not defined in System.Windows.dll assembly. In Beta1, ContentPresenter is in System.Windows.Controls.dll, and thus its Foreground property is considered as a custom DP. In Beta2, System.Windows.Controls.dll will be merged to System.Windows.dll. Also the restriction of animation on custom DP is likely to be removed. I can't 100% assure you this feature at this time though...

     

    Monday, May 19, 2008 11:15 PM