40
Record BackgroundHoverProperty is not resetting
posted

Hi,

I am facing a performance issue in XamDataGrid.

According to my requirement grid BackgroundSelectedProperty and BackgroundHoverProperty should be green initially

Based on some condition i am trying to change the color to one of selectedrecords to lightcyan in grid. 

private void HighlightRecord(XamDataGrid grid, string cid)
{
if (grid == null)
return;
Style lightCyanStyle = new Style(typeof(DataRecordCellArea));
lightCyanStyle.Setters.Add(new Setter(DataRecordCellArea.BackgroundHoverProperty, Brushes.LightCyan));
lightCyanStyle.Setters.Add(new Setter(DataRecordCellArea.BackgroundSelectedProperty, Brushes.LightCyan));
if (grid.Records != null)
{
foreach (var eachRecord in grid.SelectedRecords)
{
var record = eachRecord as DataRecord;
if (record != null && ((DataRowView)(record).DataItem).Row.Table.Columns.Contains("COLUMN"))
{
var id = ((DataRowView)(record).DataItem).Row["COLUMN"];
if (cid == Convert.ToString(id, CultureInfo.InvariantCulture))
{
RecordPresenter recordPresenter = RecordPresenter.FromRecord(record);
DataRecordCellArea cellArea =
Infragistics.Windows.Utilities.GetDescendantFromType(RecordPresenter.FromRecord(record),
typeof(DataRecordCellArea), true) as DataRecordCellArea;
if (recordPresenter != null)
{
if (cellArea != null)
cellArea.Style = lightCyanStyle;
}
break;
}
}
}
}
}

Once after Deselection I am trying to reset my grid BackgroundSelectedProperty and BackgroundHoverProperty to green

To Achieve this i tried using below code but it is not working

grid.FieldLayoutSettings.DataRecordCellAreaStyle = GreenStyle;

So i am trying to iterate for eachrecord and applying my styles back which is causing a performance issue. 

private void ResetGridRecordColor(XamDataGrid grid)
{
if (grid?.Records != null && grid.Records.Count > 0)
{

Style GreenStyle = new Style(typeof(DataRecordCellArea));
GreenStyle.Setters.Add(new Setter(DataRecordCellArea.BackgroundHoverProperty, Brushes.Green));
GreenStyle.Setters.Add(new Setter(DataRecordCellArea.BackgroundSelectedProperty, Brushes.Green));


foreach (var eachRecord in grid.Records)
{
var record = eachRecord as DataRecord;
var recordPresenter = RecordPresenter.FromRecord(record);
if (record != null && RecordPresenter.FromRecord(record) != null)
{
DataRecordCellArea cellArea =
Infragistics.Windows.Utilities.GetDescendantFromType(RecordPresenter.FromRecord(record),
typeof(DataRecordCellArea), true) as DataRecordCellArea;
if (recordPresenter != null && cellArea != null)
{
cellArea.Style = GreenStyle;
}
}
}
}
}

Could you please provide me a solution for this problem