Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to change TextBlock default properties for a ContentPresenter in a template
    primarykey
    data
    text
    <p>Based on the following code :</p> <pre><code>&lt;GroupBox&gt; &lt;GroupBox.Template&gt; &lt;ControlTemplate TargetType="{x:Type GroupBox}"&gt; &lt;ContentPresenter TextElement.FontSize="28" /&gt; &lt;/ControlTemplate&gt; &lt;/GroupBox.Template&gt; &lt;TextBlock&gt;Test&lt;/TextBlock&gt; &lt;/GroupBox&gt; </code></pre> <p>I was expecting "Test" to be displayed with FontSize=28. But it uses the default size instead.</p> <p>If I remove the TextBlock like this :</p> <pre><code>&lt;GroupBox&gt; &lt;GroupBox.Template&gt; &lt;ControlTemplate TargetType="{x:Type GroupBox}"&gt; &lt;ContentPresenter TextElement.FontSize="28" /&gt; &lt;/ControlTemplate&gt; &lt;/GroupBox.Template&gt; Test &lt;/GroupBox&gt; </code></pre> <p>The text is now the displayed with 28 as FontSize.</p> <p>Shouldn't the property value be inherited when I use a TextBlock ?</p> <p>This other question <a href="https://stackoverflow.com/questions/401600/how-do-i-change-the-fontfamily-on-a-contentpresenter">How do I Change the FontFamily on a ContentPresenter?</a> doesn't help, as it works only for default content too.</p> <p>This question also : <a href="https://stackoverflow.com/questions/401600/how-do-i-change-the-fontfamily-on-a-contentpresenter">How do I Change the FontFamily on a ContentPresenter?</a>.</p> <p>Both works whe you use the default content handler, but fails when you manually create a textblock.</p> <p>Edit: As demonstrated in <a href="https://stackoverflow.com/questions/3063264/contentpresenter-within-controltemplate-cannot-change-attached-dependency-propert">this other question</a>, I've tried by simply using a ContentControl :</p> <pre><code>&lt;StackPanel&gt; &lt;StackPanel.Resources&gt; &lt;ControlTemplate x:Key="UsingBorderTemplate" TargetType="{x:Type ContentControl}"&gt; &lt;Border BorderBrush="Red" BorderThickness="1" TextElement.FontFamily="Courier New" Margin="5"&gt; &lt;ContentPresenter/&gt; &lt;/Border&gt; &lt;/ControlTemplate&gt; &lt;ControlTemplate x:Key="MyTemplate" TargetType="{x:Type ContentControl}"&gt; &lt;ContentPresenter TextElement.FontFamily="Courier New" Margin="5" /&gt; &lt;/ControlTemplate&gt; &lt;/StackPanel.Resources&gt; &lt;ContentControl Template="{StaticResource MyTemplate}"&gt; I'm courier new! &lt;/ContentControl&gt; &lt;ContentControl Template="{StaticResource MyTemplate}"&gt; &lt;TextBlock&gt;I'm default!&lt;/TextBlock&gt; &lt;/ContentControl&gt; &lt;/StackPanel&gt; </code></pre> <p>You can change the template from "MyTemplate" to "UsingBorderTemplate" with the same result.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload