I have a need to occasionally set some styling based on the value of a cell (for example, if the Status cell is "Normal" then leave it alone, but if the Status cell is "Emergency" then turn the text red).
I attempted to handle this by using the RowLoaded() event and querying the data there, and setting the values, i.e.
This "sort of" works. The problem is that as I scroll through the records, the Forecolor changes on other items, ones that are NOT marked as Emergency.
In order to better explain, here is a short video of the problem occurring. Using the code above, only items with a status of StatEmergent should be Red (Stroke is Blue). Look at the top items that are initially black. Watch as I scroll down, then scroll up again. You will see the red text start to "bleed" onto rows where it doesn't belong
http://screencast.com/t/NGYxMjcyNm
I was hoping I could perhaps set the styling using the CellStyle property in XAML, however I am not sure how to make that dependent on the cell value?
I attempted to handle this by using the RowLoaded() event and querying the data there, and setting the values, i.e.
// Get a handle to both the data and the element |
var data = e.DataElement as WLStudyData; |
var row = e.Row as GridViewRow; |
if (data == null || row == null) return; |
if (data.Status == Status.Emergency.ToString()) |
row.Cells[4].Foreground = new SolidColorBrush(Colors.Red); |
This "sort of" works. The problem is that as I scroll through the records, the Forecolor changes on other items, ones that are NOT marked as Emergency.
In order to better explain, here is a short video of the problem occurring. Using the code above, only items with a status of StatEmergent should be Red (Stroke is Blue). Look at the top items that are initially black. Watch as I scroll down, then scroll up again. You will see the red text start to "bleed" onto rows where it doesn't belong
http://screencast.com/t/NGYxMjcyNm
I was hoping I could perhaps set the styling using the CellStyle property in XAML, however I am not sure how to make that dependent on the cell value?