Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Reason for this behaviour is <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.contentpresenter.recognizesaccesskey%28v=vs.100%29.aspx" rel="noreferrer">ContentPresenter.RecognizesAccessKey</a> which is by default <code>true</code> for <code>datagrid header contentPresenter</code>. If this property is true, it uses <code>AccessText</code> in text of header.</p> <p>Workaround for this is to hook to <code>AutoGeneratingColumn</code> event of dataGrid and replace all single underscore with double underscores. Sample is shown below - </p> <pre><code>&lt;DataGrid AutoGeneratingColumn="DataGrid_AutoGeneratingColumn"/&gt; </code></pre> <p>and in event handler -</p> <pre><code>private void DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e) { e.Column.Header = e.Column.Header.ToString().Replace("_", "__"); } </code></pre> <hr> <p>Also you can achieve that by <code>overriding ContentTemplate</code> of <code>DataGridColumnHeader</code>. Use <code>TextBlock</code> inside it which does not recognizes access key from a text.</p> <pre><code>&lt;DataGrid ItemsSource="{Binding Objects}"&gt; &lt;DataGrid.ColumnHeaderStyle&gt; &lt;Style TargetType="{x:Type DataGridColumnHeader}" BasedOn="{StaticResource {x:Type DataGridColumnHeader}}"&gt; &lt;Setter Property="ContentTemplate"&gt; &lt;Setter.Value&gt; &lt;DataTemplate&gt; &lt;TextBlock Text="{TemplateBinding Content}" HorizontalAlignment="Center"/&gt; &lt;/DataTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/DataGrid.ColumnHeaderStyle&gt; &lt;/DataGrid&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