with xamGrid, I want to change cell font color based on the data from datasource. For example, one column named status with following kind of value:
1. Good
2. Bad
3. Not sure
then I want to all Bad status dispalyed as red font, and Good status displayed as green font.
How to implement this either in xaml or in code?
Hi,
You can try the ConditionalFormatting feature of the XamGrid. This documentation article will geive you more information about this feature - http://help.infragistics.com/NetAdvantage/Silverlight/2010.3/CLR4.0/?page=xamGrid_Conditional_Formatting.html;
For the case that you describe, given that the dataType of the column is string, you can use the following snippet:
<ig:XamGrid> <ig:XamGrid.ConditionalFormattingSettings> <ig:ConditionalFormattingSettings AllowConditionalFormatting="True" /> </ig:XamGrid.ConditionalFormattingSettings> <ig:XamGrid.Columns> <ig:TextColumn Key="MyColumnKey"> <ig:TextColumn.ConditionalFormatCollection> <ig:EqualToConditionalFormatRule Value="Good"> <ig:EqualToConditionalFormatRule.StyleToApply> <Style TargetType="ig:ConditionalFormattingCellControl"> <Setter Property="Foreground" Value="Green" /> </Style> </ig:EqualToConditionalFormatRule.StyleToApply> </ig:EqualToConditionalFormatRule> <ig:EqualToConditionalFormatRule Value="Bad"> <ig:EqualToConditionalFormatRule.StyleToApply> <Style TargetType="ig:ConditionalFormattingCellControl"> <Setter Property="Foreground" Value="Red" /> </Style> </ig:EqualToConditionalFormatRule.StyleToApply> </ig:EqualToConditionalFormatRule> </ig:TextColumn.ConditionalFormatCollection> </ig:TextColumn> </ig:XamGrid.Columns> ...
HTH
Hi, tried following way:
<ig:TextColumn.ConditionalFormatCollection> <ig:EqualToConditionalFormatRule Value="Bad"> <ig:EqualToConditionalFormatRule.StyleToApply> <Style TargetType="ig:EqualToConditionalFormatRule"> <Setter Property="Foreground" Value="Red"></Setter> </Style> </ig:EqualToConditionalFormatRule.StyleToApply> </ig:EqualToConditionalFormatRule></ig:TextColumn.ConditionalFormatCollection>
and got error said:
Property 'Foreground' was not found in type EqualToConditionalFormatRule