0
votes

I have a DataGrid with four columns that will have a control in each column for each row. Whenever I select one of the controls in a column whichever row it belongs to gets highlighted white. The background will be white so the controls still show. I don't want the row to highlight at all.

<DataGrid>
<DataGrid.Columns>                                                                 
    <DataGridTemplateColumn>                                                                                                         
        <DataGridTemplateColumn.CellTemplate>                                                                                                                    
            <DataTemplate>
                <TextBox />
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
    <DataGridTemplateColumn >
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <Button />
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
    <DataGridTemplateColumn>
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <TextBox />
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
    <DataGridTemplateColumn>
        <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <Button />
            </DataTemplate>
        </DataGridTemplateColumn.CellTemplate>
    </DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>         
2
The suggestions there help abit. I am able now when I am selected on the row some of the white is covered up. Some still shows and after I click off the datagrid the row that was most recently selected still has this white highlighting in it. - user1670407
Have you tried styling the DataGrid using its CellStyle? - Kcvin
Ive tried, CellStyle, RowStyle, ColumnStyle, a bunch with the IsSelected Trigger settings the border and background and nothing seems to get rid of it. - user1670407
the second answer here might help - Kcvin

2 Answers

1
votes

You need to override HighlightBrushKey for your DataGrid but in case you set that to white, highlighted text also corresponds to white color so that won't be visible.

So, basically you need to override HighlightBrushKey to White and HighlightTextBrushKey to Black to make it work. This is how you override it -

<DataGrid>
  <DataGrid.Resources>
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                     Color="White"/>
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}"
                     Color="Black"/>
  </DataGrid.Resources>
</DataGrid>
0
votes

Try this

<DataGrid SelectionMode="Single" SelectionUnit="Cell"