The problem that you refer to when doing scroll has to do with how the visual elements of the DataGrid are managed.
The DataGridRow, DataGridCell objects, etc., are created and dropped depending on whether they are visible or not.
Note that the response code to this question requires the row to be visible in order to get a reference to the DataGridRow .
So that the problem does not arise, cell color information must be available whenever the cell needs to be re-created.
To change the background color of a cell statically, define a DataGrid.CellStyle
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="Red" />
</Style>
</DataGrid.CellStyle>
All cells will have a red background.
If you want only one or a few cells to have their color changed, you need to save this information somewhere.
Normally the color is a function of the value of the cell.
Another way is the value of the cell, in this case a class, to have a property that indicates the color.
Example where the color is set in the CorDoFundo
property:
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="{Binding CorDoFundo}" />
</Style>