开发者

background color issue in datagrid (WPF)

开发者 https://www.devze.com 2022-12-30 08:00 出处:网络
How to select a row(e开发者_StackOverflow中文版.g.first row in datagrid) and set its background color to be e.g. red in C#?

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消