I have a wpf window which has a xamdatagrid and a user control. The grid's columns represent horus of the day and its rows are days of the year. The grids' bound objects have a property for each hour of the day.
The user control allows users to populates a DateTime collection.
When the user changes their DateTime collection, I want to iterate through cells of my XamDataGrid, testing each one to see if its corresponding DateTime is included in the user's selection If it is, I want to highlight that cell.
Iterating through all records and cells would be quite heavy on performance. I would suggest setting up a style for CellValuePresenter, and assigning this style only to the field holding the data you will be comparing.
You can use MultiBinding and pass the value of the cell and the collection of input to a converter for comparison, allowing you to control the background of the cell based on the output of the converter.
Should you still wish to iterate trough all cells, you will need a foreach loop for DataRecords, and another nested one for Cells.
Please let me know if you have questions or snippet for any of the above listed options.
Sincerely,Tihomir TonevAssociate Software DeveloperInfragistics
How would I go about running the grid data through the converter after the user selects a new list of date times?
I could use some assistance with this still. I'm not entirely sure how to set the background on specific cells, not fields, in my XamDataGrid. I also do not understand how to force the styles to run through the converter logic after my DateTime collection has been updated.
Could you generate a sample project which shows some of these concepts?
I have prepared a sample which iterates trough cells and highlights them if their value matches the query. Here is a snippet for the method that I use:
private void HighlightCell(string value)
XamDataGrid grid = this.xamDataGrid1;
foreach(var record in grid.Records)
foreach(var cell in (record as DataRecord).Cells)
if (cell.Value.ToString() == value)
CellValuePresenter.FromCell(cell).Background = Brushes.Yellow;
Please note that this method will work well comparing strings only, however you can extend it to perform for numeric values as well, since the formatting there will require further checks.
Regarding your question about cell styling, each cell holds a CellValuePresenter, which is responsible for the visual representation of the cell. You can change its existing properties, as I have changed the background, or completely redesign it its needed.
Should you have any further questions, please let me know.Sincerely,Tihomir TonevAssociate Software DeveloperInfragistics