Hello,
I noticed a strange behavior when using the calculation manager and having more then one fields that are calculated that use input fields that are themself calculated: If the input fields are placed after the calculated field (later in the visual tree) then the calculation only works for the first calculated field. If the input fields are placed in front of the calculated fields then everything works fine.
I attached a solution that illustrates the issue. The BSA field is not calculated in the first example and you can see there are "Invalid reference" errors. The second example however works fine.
Do you have any Ideas what could be the issue here?
Hope to hear from you soonJohannes
Hello Johannes,
Thank you for your post. I have been looking into your issue and it seems that it occurs because you are setting the formula which contains objects before to be initialized. In your second scenario the editors that you refer in the formula are created before that and everything goes right. To achieve the desired behavior in the first scenario you can handle the ‘ValueChanged’ event of the editor with id “Weight” and put the formulas in its body like e.g. :
private void XamNumericEditor_ValueChanged(object sender, System.Windows.RoutedPropertyChangedEventArgs<object> e)
{
ControlCalculationSettings calcSettings1 = new ControlCalculationSettings();
calcSettings1.Formula = "0.007184 * power([//Height], 0.725) * power([//Weight], 0.425)";
XamCalculationManager.SetControlSettings(xneResult2, calcSettings1);
XamCalculationManager.SetCalculationManager(xneResult2, CalculationManager);
ControlCalculationSettings calcSettings2 = new ControlCalculationSettings();
calcSettings2.Formula = "10000 * [//Weight] / [//Height] / [//Height]";
XamCalculationManager.SetControlSettings(xneResult1, calcSettings2);
XamCalculationManager.SetCalculationManager(xneResult1, CalculationManager);
}
Let me know, if you need any further assistance on this matter.
Hi Yanko,
thanks for the reply. Well, this does not help me much. This was just an example. Our forms are created dynamically, there is no way of telling where a field is put on the form. And also: if I remove the BMI field, the BSA field will be calculated. Why is it possible to calculated one field but not the other?
RegardsJohannes