ComponentOne Binding Expressions for WPF and Silverlight
Introduction to Binding Expressions / The C1CalcEngine Class / C1CalcEngine Usage Scenarios
In This Topic
    C1CalcEngine Usage Scenarios
    In This Topic

    Calculated TextBox:
    Suppose you want to add a calculated TextBox to your application. Users should be able to type expressions into the TextBox. The expressions should be evaluated when the control loses focus or when the user presses Enter. You could do this with the following code:

    XAML
    Copy Code
    publicMainWindow()
     {
       InitializeComponent();
       var tb = new TextBox();
       tb.LostFocus += (s,e) => { Evaluate(s); };
       tb.KeyDown += (s, e) => { Evaluate(s); };
     }
     void Evaluate(object sender)
     {
       var tb = sender as TextBox;
       var ce = new C1.WPF.Binding.C1CalcEngine();
       try
       {
         var value = ce.Evaluate(tb.Text);
         tb.Text = value.ToString();
       }
       catch (Exception x)
       {
         MessageBox.Show("Error in Expression: " + x.Message);
       }
     }
    

    Turning Grids into Spreadsheets:
    Another typical use for the C1CalcEngine class is the implementation of calculated cells in grid controls and data objects. We have used it to implement several samples that add spreadsheet functionality to grid controls. The code is too long to include here, but you can see one of the samples in action here: http://demos.componentone.com/Silverlight/ExcelBook/.