I have a WPF application that uses Caliburn.Micro. I have a DataGrid:
<DataGrid x:Name="WeatherStations"
Grid.Row="0"
AutoGenerateColumns="False"
BaseControls:DataGridExtension.Columns="{Binding WeatherStationColumns}"
CanUserAddRows="False" IsReadOnly="True"
SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}"
SelectedItem="{Binding Path=SelectedWeatherStation, Mode=TwoWay}">
</DataGrid>
Because of some mysterious reason data in some cells of one of the columns is displayed with red foreground. I can’t find what could cause this, and I don’t see anything special about data in those particular cells, as the neighboring cells contain similar data, and yet that data is in black color.
What is even more strange, initially I have only a few cells with red foreground, but after I scroll down, most of the cells in that particular columns become red.
As you scroll, a DataGrid will reuse cells for the new data being displayed. This is a process called “virtualization”. If you are setting foreground color of the the cell via a behavior or in code-behind, that foreground color will stay with the cell even if the cells value is replaced via virtualization.
I have a hunch that somewhere in
BaseControls:DataGridExtension.Columnsyou are setting the foreground color. When the page loads and before scrolling, the values of the red cells will probably all have something in common (all negative, below a certain threshold, erroneous, etc.). Find where that is being set in your code (code-behind or markup) and that should give you a good start in solving the issue.