How can custom functions for XamCalculationManager can be implemented and used in XamFormulaEditor and also create a custom Category group in FormulaEditorDialog .
I have created a sample application that demonstrates how you can create custom functions for the XamCalculationManager and use them with XamFormulaEditor. There are two approaches for implementing custom functions for xamCalculationManager, that are shown in the attached application:
1. Using the CustomCalculationFunction. You can create an instance of the CustomCalculationFunction class and using a lambda expression to create the body of the function. To do that you can use the following constructor of that class: http://help.infragistics.com/NetAdvantage/WPF/2012.1/CLR4.0/?page=InfragisticsWPF4.Calculations.XamCalculationManager.v12.1~Infragistics.Calculations.CustomCalculationFunction~_ctor(String,Func{Double,Double}).html and pass the name of the new function and the function itself. Here is an example for doing so:
CustomCalculationFunction absAvg = new CustomCalculationFunction("AbsAvg", (x, y) => (System.Math.Abs(x) + System.Math.Abs(y)) / 2);
2. Inheriting from CalculationFunction. You can create a class that derives from the CalculationFunction abstract class (http://help.infragistics.com/NetAdvantage/WPF/2012.1/CLR4.0/?page=InfragisticsWPF4.Calculations.XamCalculationManager.v12.1~Infragistics.Calculations.Engine.CalculationFunction.html). After doing so, you can implement the abstract members of the function there. When using this approach for creating a custom function, you have more accurate control to the function itself. For example you can create own categories of functions, which appear at the left tree of FormulaEditorDialog, by overriding the Category property. If you return string that does not match an existing one, it will appear as new category. Here is an example:
public class MyCustomFunction : CalculationFunction { .... public override string Category { get { return "My Funciton Group"; } } .... }
If you return “My Custom Function” in the Category property, in the Category tree, in FormulaEditorDialog, you will have a new node with that name and your custom function in it
After you have created the custom function for your XamCalculationManager you can register the function as follows:
CalculationManager.RegisterUserDefinedFunction(absAvg);
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support