Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF globally styling a TextBlock inside a DataGrid
    text
    copied!<p>I am encountering a very weird issue. I am trying to apply global styling to several controls within a <code>DataGrid</code>. Most of them work exactly how I would expect them to. However, the styling for the <code>TextBlock</code> never gets applied. Styles for <code>ComboBox</code>, <code>TextBox</code>, <code>Label</code>, and several others all are getting applied to their respective controls, but not the <code>TextBlock</code>. I have simplified the code as much as possible and the issue is still present. I have provided the code sample below.</p> <p>I need the style to be applied to the <code>TextBlock</code> and I don't want to have to apply it manually to the <code>TextBlock</code>.</p> <pre><code>&lt;DataGrid ItemsSource="{Binding Data}" AutoGenerateColumns="False"&gt; &lt;DataGrid.Resources&gt; &lt;Style TargetType="TextBlock"&gt; &lt;Setter Property="ANY_TEXTBLOCK_PROPERTY" Value="VALUE" /&gt; &lt;/Style&gt; &lt;/DataGrid.Resources&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTemplateColumn Header="Test"&gt; &lt;DataGridTemplateColumn.CellTemplate&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="Globably Applied" /&gt; &lt;/DataTemplate&gt; &lt;/DataGridTemplateColumn.CellTemplate&gt; &lt;/DataGridTemplateColumn&gt; &lt;/DataGrid.Columns&gt; &lt;/DataGrid&gt; </code></pre> <p><strong>More Information:</strong></p> <ul> <li>Global styles for any control other than <code>TextBlock</code> (<code>TextBox</code>, <code>ComboBox</code>, etc.) work properly.</li> <li>Defining the global style inside the <code>DataTemplate</code> will work properly.</li> <li>Directly assigning the style to the <code>TextBlock</code> using an <code>x:Key</code> will work.</li> <li>Global styles for <code>DataGridCell</code> using <code>TextElement.PROPERTY</code> will get applied to a <code>TextBlock</code>.</li> </ul> <p>While some of these will get the style applied to the <code>TextBlock</code>, they have there own issues. Directly assigning the style or defining the style somewhere within a <code>DataGridColumn</code> will mean that I will have to apply the style more than once. Using the <code>TextElement.PROPERTY</code> on the <code>DataGridCell</code> will apply the style to more than just <code>TextBlock</code> controls and will limit the number of properties that you can set.</p>
 

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