How can I set the color of a selected row in DataGrid

后端 未结 8 1589

The default background color of a selected row in DataGrid is so dark that I can\'t read it. Is there anyway of overriding it?

Tried this



        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 20:20

    I had this problem and I nearly tore my hair out, and I wasn't able to find the appropriate answer on the net. I was trying to control the background color of the selected row in a WPF DataGrid. It just wouldn't do it. In my case, the reason was that I also had a CellStyle in my datagrid, and the CellStyle overrode the RowStyle I was setting. Interestingly so, because the CellStyle wasn't even setting the background color, which was instead bing set by the RowBackground and AlternateRowBackground properties. Nevertheless, trying to set the background colour of the selected row did not work at all when I did this:

            
            
                ...
            
            
                ...
            
            
                
            
            
                
            
    

    and it did work when I moved the desired style for the selected row out of the row style and into the cell style, like so:

        
            
                ...
            
            
                ...
            
            
                
            
    

    Just posting this in case someone has the same problem.

提交回复
热议问题