Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
375
XamCalculationManager: Issue with multiple calculated fields
posted

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 soon
Johannes 

MultipleCalculations.zip
Parents
  • 35319
    posted

    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.

Reply Children