background color issue in datagrid (WPF)
How to select a row(e开发者_StackOverflow中文版.g.first row in datagrid) and set its background color to be e.g. red in C#?
I have following code in my program:
gameDataGrid.RowBackground = new SolidColorBrush(Colors.Red);
The output's background is not red.
If you are wanting to change multiple rows based on some property, wire up the LoadingRow event and change the DataGridRow's style in the event handler.
in xaml
<DataGrid
AlternatingRowBackground="AliceBlue"
CanUserAddRows="false"
CanUserSortColumns="False"
Grid.Row="2"
Foreground="#FF040404"
Background="#cce6ff"
VirtualizingStackPanel.VirtualizationMode = "recycling"
VirtualizingStackPanel.IsVirtualizing = "true"
EnableColumnVirtualization = "true"
EnableRowVirtualization = "true"
x:Name="dvSalesEntryDataGrid"
AlternationCount="2"
AutoGenerateColumns="False">
</DataGrid>
精彩评论