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?
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?
There is no reply to my query yet.
This is a very basic requirement for any trading application.Even after creating the custom rule it does not get appied to real time data change...even after setting the
i am waiting for your reply since past four days.
Testing out your claim, I have a sample that updates the field and processes the information. At this point, if you still can't resolve your issue, I am going to need a working test sample demonstrating what you are seeing.
If your data object implements INotifyPropertyChanged then we can see the object's values changing (assuming the properties raised the event)
IF you are changing the collection , then the collection should implement INotifyCollectionChanged (like observable collection).
i am unable to find the following dlls so unable to run your test project.i am using Vesion 10.3.
Infragistics.Silverlight.dll
Infragistics.Silverlight.XamWebGrid.dll
Those are the two dlls for the XamGrid. You would need to add those references.