I i'm triyng to change the background of every cell on my xamdatagrid so it appears like a chess, but in this simplier example im only tryinh to reproduce stripes like one record is AliceBlue and the other green then alice blue then green etc.
But with this code the xamdatagrid ("dataGridCampaignPriority") is getting always green.
int count = 0; foreach (Record rec in dataGridCampaignPriority.Records) { DataRecord dr = rec as DataRecord; foreach (Cell cell in dr.Cells) { if(count%2==0) cell.DataPresenter.Background = Brushes.AliceBlue; else cell.DataPresenter.Background = Brushes.Green; } count++; }
Thank you for the help
Hello,
The DataPresenter property will return the DataPresenterBase element - the XamDataGrid. What you are seeing probably is change of the background color of the whole grid and not the cell?
What you need to do is get the CellValuePresenter - the visual representation of the cell and set its background. Another way would be to use a converter (IValueConverter or IMultiValueConverter) and set it to the background of the CVP.
1. CVP you can get by calling the CellValuePresenter.FromCell(...) method.
2. For using converter, you may want to take a look at this forum thread : http://community.infragistics.com/forums/t/20644.aspx?PageIndex=1