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
Thank you. Tried your suggestion as below:
<ig:TextColumn Key="Status" > <ig:TextColumn.HeaderTemplate> <DataTemplate> <TextBlock Text="{Binding Path=HeaderStatus,Source={StaticResource localizedStrings}}" /> </DataTemplate> </ig:TextColumn.HeaderTemplate> <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>
The run the app, no error. but nothing happened. The column Status same as before with no color changed.