Note that there are some explanatory texts on larger screens.

plurals
  1. POBinding ContentPresenter.Content to TemplatedParent (WPF/Silverlight)
    primarykey
    data
    text
    <p>Basically, I would like to overlay, for example: <code>TextBlock</code> over <code>Button</code>, by using <code>ControlTemplate</code> (applied to this <code>Button</code>), but I don't want to get rid of default template of it.</p> <p>Example:</p> <pre><code>&lt;Grid Grid.Row="1" Grid.ColumnSpan="2"&gt; &lt;Grid.Resources&gt; &lt;Style x:Key="myStyle" TargetType="Button"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="Button"&gt; &lt;Grid&gt; &lt;ContentPresenter /&gt; &lt;TextBlock Text="textBlock" Margin="10" Foreground="Red"/&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/Grid.Resources&gt; &lt;Button Style="{StaticResource myStyle}" Content="button1"&gt;&lt;/Button&gt; &lt;/Grid&gt; </code></pre> <p>and it gives <code>Button</code> stripped of it's default template:</p> <p><img src="https://i.stack.imgur.com/j5gqN.gif" alt="enter image description here"></p> <p>Rather, I would like to receive something like this:</p> <p><img src="https://i.stack.imgur.com/Q5Mmz.gif" alt="enter image description here"></p> <p>Is it possible by using <code>ControlTemplate</code>? I was trying to bind <code>TemplatedParent</code> to <code>ContentPresenter.Content</code> like here:</p> <pre><code>&lt;ContentPresenter Content="{Binding RelativeSource={RelativeSource Mode=TemplatedParent}, Path=., Mode=TwoWay}"/&gt; </code></pre> <p>or other combinations, but I couldn't make it work.</p> <p><strong>Edit:</strong></p> <p>Because I would like to be able to apply this <code>TextBlock</code> not only to a button (it was just an example) but to any <code>Control</code>, I don't want do it by copying default style (to the resources or somewhere), for every <code>Control</code>. Also, I would prefer not to create <code>UserControl</code>, because I would like to keep xaml clean as much as possible (I mean with system Controls) - and just to turn on/off the overlaying <code>TextBlock</code> by using a <code>ControlTemplate</code>.</p>
    singulars
    1. This table or related slice is empty.
    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. 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