Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is because <code>ContentPresenter</code> creates a TextBlock for a string content, and since that TextBlock isn't in the visual tree, it will lookup to Application level resource. And if you define a style for TextBlock at Application level, then it will be applied to these TextBlock within ControlControls.</p> <p>A workaround is to define a <code>DataTemplate</code> for <code>System.String</code>, where we can explicitly use a default TextBlock to display the content. You can place that DataTemplate in the same dictionary you define the TextBlock style so that this DataTemplate will be applied to whatever ContentPresenter effected by your style.</p> <p>Add this to your Application resources and it should work for you - </p> <pre><code>&lt;DataTemplate DataType="{x:Type system:String}"&gt; &lt;TextBlock Text="{Binding}"&gt; &lt;TextBlock.Resources&gt; &lt;Style TargetType="{x:Type TextBlock}"/&gt; &lt;/TextBlock.Resources&gt; &lt;/TextBlock&gt; &lt;/DataTemplate&gt; </code></pre> <p>Declare a namespace in your xaml, if not referred already -</p> <pre><code>xmlns:system="clr-namespace:System;assembly=mscorlib" </code></pre> <p><strong>EDIT : Check this sample where its working..</strong></p> <pre><code>&lt;Style TargetType="{x:Type TextBlock}"&gt; &lt;Setter Property="Foreground" Value="Red"/&gt; &lt;/Style&gt; &lt;DataTemplate DataType="{x:Type system:String}"&gt; &lt;TextBlock Text="{Binding}"&gt; &lt;TextBlock.Resources&gt; &lt;Style TargetType="{x:Type TextBlock}"/&gt; &lt;/TextBlock.Resources&gt; &lt;/TextBlock&gt; &lt;/DataTemplate&gt; &lt;Style TargetType="{x:Type Button}"&gt; &lt;Setter Property="Foreground" Value="Yellow"/&gt; &lt;/Style&gt; &lt;Style TargetType="{x:Type Label}"&gt; &lt;Setter Property="Foreground" Value="Blue"/&gt; &lt;/Style&gt; </code></pre>
    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. This table or related slice is empty.
    1. VO
      singulars
      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