关于 wpf dataGrid 选中行 失去焦点时 的背景颜色的更改。很简单的方式,在datagrid的resource中更改InactiveSelectionHighlightBrushKey属性的值即可。
关键代码如下:
<DataGrid.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Yellow"/> </DataGrid.Resources>
完整的简单代码如下:
<DataGrid Name="grid1" HorizontalAlignment="Left" Height="120" Margin="75,86,0,0" VerticalAlignment="Top" Width="282"> <DataGrid.Columns> <DataGridTextColumn Header="编号" Binding="{Binding compan.ID}"></DataGridTextColumn> <DataGridTextColumn Header="公司" Binding="{Binding CompanyName}"></DataGridTextColumn> <DataGridTextColumn Header="固定资产" Binding="{Binding FixedAssets}" Width ="*"></DataGridTextColumn> </DataGrid.Columns> <DataGrid.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Yellow"/> </DataGrid.Resources> </DataGrid>