I need to compare a cell value with its new value and accordingly change its background to green if cell new value is higher else to red if cells new value is smaller. i also want a upward/ downward arrow besides it.
can you help me with this requirement. should i use conditional formatting or valueconvertor?
how to go about it?
There is nothing in the XamGrid that is going to remember your old value, so you would need to persist that value on your data object and then write a custom conditional formatting rule and make your evaluation.
You could use the IconConditionalFormattingRule as your base class for your custom rule because that will allow you to put icons into the cells.
... and then write a custom conditional formatting rule and make your evaluation...
Is there an example for this?
http://community.infragistics.com/forums/p/53040/275151.aspx#275151
Hi, i craeted custom rule where i am passing my styles which are created dynamically depeding upon user setting of color for background and foreground. however even after setting the rule property
MyRule.ShouldRefreshOnDataChange = true;
the rule is applied only at first time while loading grid with data. when i start realtime update it does not change depending on rule.
can you tell me where i am going wrong.
my code is something like this
ConditionalFormattingRuleBase
{
; }
obj)
.StyleUp = Styleup;
.StyleDown = Styledown;
objUpDownColourRuleConfig = obj;
}
CreateProxy()
(StyleUp, StyleDown, objUpDownColourRuleConfig);
ConditionalFormattingRuleBaseProxy
NewDataObject)
)
;
)OrigDataObject;
));
(iNewVal > iOrigVal)
.StyleUp;
(iNewVal < iOrigVal)
.StyleDown;
And i am dynamically adding the rule from code behind lke this
#region
Up/Down Colour Rule
Dictionary<string, UpDownColourRuleConfig> dictUpDownColorRuleConfig = viewmodelobj.dictUpDownColourRuleConfig;
if (dictUpDownColorRuleConfig != null && dictUpDownColorRuleConfig.Count > 0)
this.dataGrid.ConditionalFormattingSettings.AllowConditionalFormatting = true;
foreach (var item in dictUpDownColorRuleConfig)
Color forecolorUp = new Color();
forecolorUp.A = 255;
forecolorUp.R =
byte.Parse(item.Value.RuleUpForeColor.Substring(0, 2), NumberStyles.HexNumber);
forecolorUp.G =
byte.Parse(item.Value.RuleUpForeColor.Substring(2, 2), NumberStyles.HexNumber);
forecolorUp.B =
byte.Parse(item.Value.RuleUpForeColor.Substring(4, 2), NumberStyles.HexNumber);
SolidColorBrush sbforeGroundUp = new SolidColorBrush(forecolorUp);
Color backcolorUp = new Color();
backcolorUp.A = 255;
backcolorUp.R =
byte.Parse(item.Value.RuleUPBackColor.Substring(0, 2), NumberStyles.HexNumber);
backcolorUp.G =
byte.Parse(item.Value.RuleUPBackColor.Substring(2, 2), NumberStyles.HexNumber);
backcolorUp.B =
byte.Parse(item.Value.RuleUPBackColor.Substring(4, 2), NumberStyles.HexNumber);
SolidColorBrush sbBackGroundUp = new SolidColorBrush(backcolorUp);
Color forecolorDown = new Color();
forecolorDown.A = 255;
forecolorDown.R =
byte.Parse(item.Value.RuleDownForeColor.Substring(0, 2), NumberStyles.HexNumber);
forecolorDown.G =
byte.Parse(item.Value.RuleDownForeColor.Substring(2, 2), NumberStyles.HexNumber);
forecolorDown.B =
byte.Parse(item.Value.RuleDownForeColor.Substring(4, 2), NumberStyles.HexNumber);
SolidColorBrush sbforeGroundDown = new SolidColorBrush(forecolorDown);
Color backcolorDown = new Color();
backcolorDown.A = 255;
backcolorDown.R =
byte.Parse(item.Value.RuleDownBackColor.Substring(0, 2), NumberStyles.HexNumber);
backcolorDown.G =
byte.Parse(item.Value.RuleDownBackColor.Substring(2, 2), NumberStyles.HexNumber);
backcolorDown.B =
byte.Parse(item.Value.RuleDownBackColor.Substring(4, 2), NumberStyles.HexNumber);
SolidColorBrush sbBackGroundDown = new SolidColorBrush(backcolorDown);
Style styleUp = new Style();
styleUp.TargetType =
typeof(ConditionalFormattingCellControl);
Setter setter = new Setter();
setter.Property =
ConditionalFormattingCellControl.ForegroundProperty;
setter.Value = sbforeGroundUp;
styleUp.Setters.Add(setter);
Setter setter1 = new Setter();
setter1.Property =
ConditionalFormattingCellControl.BackgroundProperty;
setter1.Value = sbBackGroundUp;
styleUp.Setters.Add(setter1);
Setter setter2 = new Setter();
setter2.Property =
ConditionalFormattingCellControl.AltBackgroundProperty;
setter2.Value = sbBackGroundUp;
styleUp.Setters.Add(setter2);
Style styleDown = new Style();
styleDown.TargetType =
Setter setter3 = new Setter();
setter3.Property =
setter3.Value = sbforeGroundDown;
styleDown.Setters.Add(setter3);
Setter setter4 = new Setter();
setter4.Property =
setter4.Value = sbBackGroundDown;
styleDown.Setters.Add(setter4);
Setter setter5 = new Setter();
setter5.Property =
setter5.Value = sbBackGroundDown;
styleDown.Setters.Add(setter5);
UpDownConditionalFormatRule MyRule = new UpDownConditionalFormatRule(styleUp, styleDown, item.Value);
MyRule.StyleScope =
StyleScope.Cell;
MyRule.ShouldRefreshOnDataChange =
true;
dataGrid.Columns.DataColumns[item.Value.ColumnName].ConditionalFormatCollection.Add(MyRule);
#endregion
Does your data object implement INotifyPropertyChanged?
yes it does
can you update the above sample for real time data. actually i am creating styles also dynamically depending on user settings loaded from server.Also i am getting the colum name from settings to which this rule needs to be applied some thing like thsi
<DictUpDownColourRuleConfig type="map">
<
i id="IsAvailable.UpDownColourRule" type=".Sales.Controls.Models.UpDownColourRuleConfig">
RuleAppliedOn value="Column"/>
ColumnName value="Marks"/>
RuleName value="Marks.UpDownColourRule"/>
RuleUpForeColor value="000000"/>
RuleUPBackColor value="00FF00"/>
RuleDownForeColor value="000000"/>
RuleDownBackColor value="FF0000"/>
</
i>
DictUpDownColourRuleConfig>