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 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; } }
Best Regards,Yanko
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.
The example allow you to color singhe styled cell.
I also need to chenge the entire row background color.
The way is to overwrite the style DataRecordCellArea
<Style TargetType="{x:Type igDP:DataRecordCellArea}"> <Setter Property="BorderBrush" Value="Black" /> <Setter Property="BorderThickness" Value="0.5" /> <Setter Property="CornerRadius" Value="10" /> <Setter Property="Background" Value="White"/> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Content, Converter={StaticResource t}}" Value="3"> <Setter Property="Background" Value="Red" /> </DataTrigger> </Style.Triggers> </Style>
The problem is that the value is bounded to a value of a column. (my dataSource i a DataView) and at first value update the color doesn't change.
Any suggests?
Andrea
The sample available in http://forums.infragistics.com/forums/p/2701/16506.aspx#16506