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.
I've attached a sample application. If you run it you should get the following result:
Thank you. I have downloaded you code and compared each other. Codes no difference. But veriosn of Infrigistic DLL is different. Mine is 10.3 and your is 11.1.
My company have purchased Infrigistic production last week, so when we donwloaded, Infrigistic should give us the lastest version. How can I get the lastest version of Infrigistic silverlight?
NetAdvanatage 10.3 is our latest production release. So you have the lastest dlls. 11.1 will be our upcoming release.
What versions of the 10.3 dlls do you have?
The assembly for xamGrid is InfragisticsSL4.Controls.Grids.XamGrid.v10.3.
Could you plese try your solution above with this assembly and see if it's working?
By the way, when the 11.1 will be available for clients because I dont't want to spent to much time on source code at this time?
I've just tried to reproduce the issue that you describe. It appears that the problem is that you set Color for a value. The Foreground property is a Brush, you should use SolidColorBrush instead.
hi,
I solved my problem . i created a solod color brush and applied it.
Color
backcolor = new Color();
backcolor.A = 255;
backcolor.R =
byte.Parse(item.Value.RuleBackColor.Substring(0, 2), NumberStyles.HexNumber);
backcolor.G =
byte.Parse(item.Value.RuleBackColor.Substring(2, 2), NumberStyles.HexNumber);
backcolor.B =
byte.Parse(item.Value.RuleBackColor.Substring(4, 2), NumberStyles.HexNumber);
SolidColorBrush sbBackGround = new SolidColorBrush(backcolor);
Infragistics.Controls.Grids.
ColumnBase col = dataGrid.Columns[item.Value.ColumnName];
EqualToConditionalFormatRule MyRule = new EqualToConditionalFormatRule();
MyRule.Value = strColVal;
MyRule.StyleScope =
StyleScope.Cell;
Style style = new Style();
style.TargetType =
typeof(ConditionalFormattingCellControl);
Setter setter = new Setter();
setter.Property =
ConditionalFormattingCellControl.ForegroundProperty;
setter.Value = sbforeGround;
style.Setters.Add(setter);
Hi Nikolay,
I am also implementing the simailar EqualToConditionalFormatRule but i am implementing it in code behind. i am using 10.3 version dlls.
i have a requirement where the conditions are loaded at runtime and hence i am adding EqualToConditionalFormatRule in code behind.someting like this
this.dataGrid.ConditionalFormattingSettings.AllowConditionalFormatting = true;
MyRule.Value = strColVal;// this is "Y"
MyRule.StyleScope = StyleScope.Cell;
style.TargetType = typeof(ConditionalFormattingCellControl);
setter.Property = ConditionalFormattingCellControl.ForegroundProperty;
setter.Value = Colors.Red;
Setter setter1 = new Setter();
setter1.Property = ConditionalFormattingCellControl.BackgroundProperty;
setter1.Value = Colors.Yellow;
style.Setters.Add(setter1);
MyRule.StyleToApply = style;
dataGrid.Columns.DataColumns[item.Value.ColumnName].ConditionalFormatCollection.Add(MyRule);
however after adding this rule my cells with “Y” value are changed to blank.
The rule is not applied. Can you tell mw what is wrong.
Also the setter values that I have set as
I want to set them dynamically from my settings object
My settings object is like this.
<DictColorRuleConfig type="map">
<i id="IsAvailable.ColorRule" type=".Sales.Controls.Models.ColorRuleConfig">
<RuleAppliedOn value="Column"/>
<ColumnName value="IsAvailable"/>
<RuleName value="IsAvailable.ColorRule"/>
<RuleExpression value="IsAvailable=Y"/>
<RuleForeColor value="FF0000"/>
<RuleBackColor value="FFFF00"/>
</i>
</DictColorRuleConfig>
I am coverting the forcolor and back color string as color object like this
Color color = new Color();
color.A = 255;
color.R = byte.Parse(item.Value.RuleForeColor.Substring(0, 2), NumberStyles.HexNumber);
color.G = byte.Parse(item.Value.RuleForeColor.Substring(2, 2), NumberStyles.HexNumber);
color.B = byte.Parse(item.Value.RuleForeColor.Substring(4, 2), NumberStyles.HexNumber);
how do I set this color object as my style setter value?
Thank you. Figured it out: should turn ConditionalFormatting in ConditionalFormattingSettings.
The sample that I've posted will work on 10.3;
I've uploaded a new sample with fixed references. It's tested on 10.3.20103.1006 (The RTM build) and on 10.3.20103.2117 (the latest Service Release). If you run it you should get the same result as on the screenshot above.
Regards,