Hello,
I try to use your xamFormulaEditor, but I don't know how to achieve what I want, because there is no sample that fits.
What I'm trying to do is:
Step 1: Edit a formula string via xamFormulaEditor, where the operands should be 1 to n double values from an array.
Step 2: Store this string to disk. (no problem)
Step 3: Later on the program should pick up the formula string and do the calulation.
The problems are
Step 1: How can I tell the editor that there are n operands? The number of available operands will vary.
Step 3: What do I have to do in order to calculate my formula with my actual operands? There is no dialog window available at this moment.
Please could someone give me a small sample as a starter?
Maybe something with these two functions:
void OpenEditor(ref string formulaString, int numberOfOperands) // opens window to edit the formula
double Calc(string formulaString, double[] operands) // calculates the formula with the given operands
Hello Michael,
I have attached a sample where you input a number into a textbox to specify the number of arguments for a specific function named MyAvg.
After that, you need to open the FormulaEditor dialog window by pressing a button, which will update the function with the correct amount of arguments. Then it will calculate the average of the given operands.
Also, here is a link to the online documentation for the FormulaEditor: http://help.infragistics.com/Doc/WPF/Current/CLR4.0/?page=xamFormulaEditor.html
Please let me know if you have any questions or concerns.
Sincerely,AndrewDeveloper Support IInfragistics Inc.www.infragistics.com/support
Hello Andrew,
thank you for your sample.
Unfortunatly this is not quit what I need. Maybe this is due to my bad english.
1. the operands are not shown in the editor. They should be available to be selected by the user and be inserted in the formula like variables. Something like [//OP1], [//OP2] and so on.
2. I want to calculate the formula after the window and the calcManager is long since destroyed. So I tried to modify your Button2_Click event (see below) and create a new calcManager. But how can I give the calcManager the operands to use with the formula?
private void Button2_Click(object sender, RoutedEventArgs e)
{
var argumentCount = int.Parse(this.numArgs.Text);
var operands = CreateSampleOperands(argumentCount);
var formula = this.formulaEditor.Formula;
XamCalculationManager xcm = new XamCalculationManager();
xcm.RegisterUserDefinedFunction(
new CustomCalculationFunction("MyAvg", args => args.Average(), argumentCount, argumentCount));
// how to give xcm the operands before calculating?
var result = xcm.CalculateFormula(formula);
MessageBox.Show("Average: " + result.GetResolvedValue().ToString());
}