Is there an EASY way to change the background color of a row based on data in that row?
Any help will be appreciated.
Hi,
You can easily change the background of a row(record) based on the value of one of its cells using style triggers.
<igDP:XamDataGrid.Resources> <Style TargetType="{x:Type igDP:DataRecordCellArea}"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path= Record.Cells[1].Value}" Value="Sales"> <Setter Property="Background" Value="Orange" /> </DataTrigger> </Style.Triggers> </Style> </igDP:XamDataGrid.Resources>
I have created and attached a working sample application, demonstrating this approach.
Best Regards,Yanko
Hi mkassa,
<igDP:XamDataGrid.Resources> <Style TargetType="{x:Type igDP:DataRecordCellArea}"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path= Record.Cells[department].Value}" Value="Sales"> <Setter Property="Background" Value="Orange"/> </DataTrigger> </Style.Triggers> </Style></igDP:XamDataGrid.Resources>
The above-mentioned Xaml fragment can be reproduced in code behind by using the following code:
RecordCollectionBase recordsCollection = xamDataGrid1.Records;foreach (Record rec in recordsCollection) { DataRecord dataRec = (DataRecord)rec; if ("Sales" == (string)dataRec.Cells["department"].Value) { DataRecordPresenter.FromRecord(rec).Background = Brushes.Orange; } }