Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <code>DataGridColumns</code> that derive from <code>DataGridBoundColumn</code> (all except <code>DataGridTemplateColumn</code>) has a property <code>ElementStyle</code> that is applied to the <code>TextBlock</code> when it is created. For e.g. <code>DataGridTextColumn</code> It looks like this</p> <pre><code>static DataGridTextColumn() { ElementStyleProperty.OverrideMetadata(typeof(DataGridTextColumn), new FrameworkPropertyMetadata(DefaultElementStyle)); // ... } </code></pre> <p>It overrides the metadata for <code>ElementStyle</code> and provides a new default value, <code>DefaultElementStyle</code>, which basically just sets the default margin for the <code>TextBlock</code>. </p> <pre><code>public static Style DefaultElementStyle { get { if (_defaultElementStyle == null) { Style style = new Style(typeof(TextBlock)); // Use the same margin used on the TextBox to provide space for the caret style.Setters.Add(new Setter(TextBlock.MarginProperty, new Thickness(2.0, 0.0, 2.0, 0.0))); style.Seal(); _defaultElementStyle = style; } return _defaultElementStyle; } } </code></pre> <p>This style is set in code everytime a new <code>DataGridCell</code> is created with <code>element.Style = style;</code> and this is overriding the Style you are trying to set, even if you try to set it implicitly.</p> <p>As far as I know, you'll have to repeat this for your columns</p> <pre><code>&lt;DataGridTextColumn Header="Column 1" ElementStyle="{StaticResource BoldCellStyle}" .../&gt; &lt;DataGridTextColumn Header="Column 2" ElementStyle="{StaticResource BoldCellStyle}" .../&gt; </code></pre>
 

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