Restyling DataGridCell, thin white line around otherwise different background color

Apr 22, 2009 at 2:23 PM
One requirement for the application I am writing is to visually indicate the read/write vs read-only status of different cells in a DataGrid. Depending on circumstances, either the whole DataGrid instance or simply individual columns can have IsReadOnly=True.

I was able to accomplish this by modifying the template for DataGridCell, changing the background color in a trigger setter, but I am getting a thin (1 pixel) white line around the (light gray) background color of each cell, immediately inside the horizontal and vertical grid lines. It's not a problem from a technical point of view, but it doesn't look very good, so how do I set it to the same color as the cell's background color?
Apr 23, 2009 at 10:41 PM
It's hard to immediately say who this background belongs to from the changes you made.  From a visual tree can you tell which element this is that is setting the background to white (from mole or snoop)?  Maybe a repro app would be more efficient.
Apr 24, 2009 at 8:28 AM
I poked around with Mole, and took a closer look at the visual tree. It looks like the best option at least to begin with might be to restyle the DataGridCellsPanel, and when I manually set the Background on it, I get the result I am after for a whole row (which would translate to the DataGrid.IsReadOnly property), though I don't know how to apply this style based on the ancestor property. Suggestions?

However, that still leaves the problem of re-styling a column properly based on the column's IsReadOnly property. Since I'm already styling the DataGridCell, and the closest parent element in the visual tree is the DataGridCellsPanel, I tried changing the background on that one. However, that affects the entire row (obviously), rather than just the specific column that I want to change the background of.

The logical tree is significantly less helpful in this case as it stops at the DataGrid control itself.

Any insights would be greatly appreciated.