ContentPresenter within ControlTemplate cannot change attached dependency property

Posted by happyclicker on Stack Overflow See other posts from Stack Overflow or by happyclicker
Published on 2010-06-17T15:44:03Z Indexed on 2010/06/17 15:53 UTC
Read the original article Hit count: 243

Why does the following simplified code not set the font-size of the TextBlock to 50?

<Window.Resources>
    <ControlTemplate TargetType="ContentControl" x:Key="Test">
        <ContentPresenter TextBlock.FontSize="50" />
    </ControlTemplate>        
</Window.Resources>        
<Grid>
    <ContentControl Template="{StaticResource Test}">
        <TextBlock>Test should be rendered big</TextBlock>
    </ContentControl>                   
</Grid>

If I change the value of the FontSize property, visual studio shows me the text in the size I want. After compiling or executing the app, the size of the textblock is always reset to its default size.

I have also tested various versions with styles and embedded resources but I end always in the situation that I cannot set attached dp's from within a ControlTemplate that contains a ContentPresenter. Is this by design?

© Stack Overflow or respective owner

Related posts about wpf

Related posts about controltemplate