DataGridCell background coloring
-
06-10-2022 - |
Question
In my WPF application, I need to paint the background of a specific DataGridTextColumn
cell with some color. Here is what I tried:
DataGridCell cell = ...
cell.Background = Brushes.Yellow;
Upon execution, I do see a little bit of yellow color near the right edge but the color does not cover the complete cell.
I figured it must be the TextBlock content that is getting painted on top of my yellow color. Therefore, I added the following code:
TextBlock content = cell.Content as TextBlock;
content.Text = "abc";
content.Background = Brushes.Yellow;
This results in a background color behind the text "abc." The rest of the cell is still colored in white.
I am wondering if someone can point me in the right direction.
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow