Can I use a Conditional format rule to change the background of a whole row in a grid?
(For example, I have a 'grade' column in my grid. If the grade value is less than 60, I want the background color of the whole row to be red).
If not, is there some other way to achieve this?
Hello Hagit,
Thank you for your post. I have been looking into it and I created a sample project for you where I used conditional formatting in both XamGrid and XamDataGrid. Here you can find more information how to do conditional formatting in the grids:
XamDataGrid:
http://mytorrey.com/2011/05/08/conditionally-formatting-cells-in-xamdatagrid-2/
XamGrid:
http://www.infragistics.com/samples/wpf/grid/conditional-formatting-rules
Please let me know if this helps you or you have further questions on this matter.
Looking forward for your reply.
I am just checking if you got this worked out or you still require any assistance or clarification on the matter.
Sorry for my delayed reply.
I still couldn't achieve what I wanted.
I need to change the background of rows in the grid (XamGrid / XamDataGrid) according to a property of type enum that is displayed in the grid as an image.
I took the sample you have attached in your last reply, and added the following:
In MainWindow.xaml.cs
In MainWindow.xaml
<ig:TemplateColumn Key="Validity">
<ig:TemplateColumn.ItemTemplate>
<DataTemplate>
<Image Width="16" Height="16" Source="{Binding Path=Validity, Converter={StaticResource validityToImageConverter} }" />
</DataTemplate>
</ig:TemplateColumn.ItemTemplate>
…
</ig:TemplateColumn>
Now, I want to set yellow background of rows that have the Validity property set to Warning. How do I do this?
I have modified the sample further, so now it has the functionality you want. Basically I changed the way you set the Value of the Validity Column's EqualToConditionalFormatRule, because it is an Enum type. I also added a Style fort he CellValuePreseter in the XamDataGrid, so now the XamDataGrid shows the images, too. Another modification I make is moving the definition of the Enum Type outside of the ChartData class. Please let me know if this helps you or you have further questions on this matter. Looking forward for your reply.
I didn't really understand why the enum type had to be taken out of the CharData class. (This is only an example, but in my real application all the enum types belong to classes). But other than that, I got it.
Thanks a lot.