Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I found the reason of this behavior - it’s by design:</p> <p>If the Content of ContentControl is already a WPF-Element, it is <strong>created before using it in the ContenPresenter</strong>. The logical <strong>parent</strong> of the element <strong>is</strong> therefore <strong>ContentControl</strong>. I can check this through changing the ContentControl-markup to the following:</p> <pre><code>&lt;ContentControl Template="{StaticResource Test}" TextBlock.FontSize="50"&gt; &lt;TextBlock&gt; This text now is shown with a size of 50 &lt;/TextBlock&gt; &lt;/ContentControl&gt; </code></pre> <p>In this example the text size is 50 as desired. I can prove this argumentation also with wpf-visualizer of visual studio. The parent is ContentControl and through dp-inheritance, the FontSize is taken from the parent (ContentControl), and the text is shown with a size of 50!</p> <p><strong>Another behavior</strong> can be observed if the ContentControl contains only text as content:</p> <pre><code>&lt;Window.Resources&gt; &lt;ControlTemplate x:Key="Test" TargetType="{x:Type ContentControl}"&gt; &lt;ContentPresenter TextBlock.FontSize="50"/&gt; &lt;/ControlTemplate&gt; &lt;/Window.Resources&gt; &lt;Grid&gt; &lt;ContentControl Template="{StaticResource Test}"&gt; This text is shown with a size of 50 &lt;/ContentControl&gt; &lt;/Grid&gt; </code></pre> <p>In this scenario, the <strong>TextBox</strong> is <strong>created through the ContentPresenter</strong> because text cannot be entered in the visual tree. The textbox has no parent but the TemplateParent-property leads to the ContentPresenter as the TextBoxes parent and the DP-system takes the FontSize-value through attached dependency property inheritance from the ContentPresenter. That’s why in this scenario the font size is changed to 50. </p> <p>The different scenarios are described <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentpresenter.aspx" rel="noreferrer">here</a>.</p> <p>What I don’t understand is, why VS2010 shows the FontSize 50 before compiling.</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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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