0

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>         
  • http://stackoverflow.com/questions/1223280/how-can-i-set-the-color-of-a-selected-row-in-datagrid – Kcvin Dec 03 '13 at 21:03
  • 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. –  Dec 03 '13 at 21:20
  • Have you tried styling the `DataGrid` using its `CellStyle`? – Kcvin Dec 03 '13 at 21:53
  • Ive tried, CellStyle, RowStyle, ColumnStyle, a bunch with the IsSelected Trigger settings the border and background and nothing seems to get rid of it. –  Dec 03 '13 at 21:55
  • the second answer [here](http://stackoverflow.com/questions/1745272/disable-cell-highlighting-in-a-datagridview) might help – Kcvin Dec 03 '13 at 22:22
  • That seems to be for a datagridview I'm using a DataGrid. –  Dec 04 '13 at 14:22

2 Answers2

1

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>
Rohit Vats
  • 79,502
  • 12
  • 161
  • 185
0

Try this

<DataGrid SelectionMode="Single" SelectionUnit="Cell"
yo chauhan
  • 12,079
  • 4
  • 39
  • 58
  • That seems to work good except that only the column with the control that you selected now has the white highlighting rather than the whole row. –  Dec 03 '13 at 21:46