How to use Math Expression Editor Light for WPF Application?

We suggest you a simple way how to do this. Please follow steps below:

 

 

1. Create new WPF Application

You can use .NET Framework versions: 2.0/3.0/3.5/4.0/4.5/ etc.. but make sure that Client Profile is not selected

You can use .NET Framework versions: 2.0/3.0/3.5/4.0/4.5/ etc.. but make sure that Client Profile is not selected

2. Add References

  • MEEL
  • MathTree
  • Ststem.Windows.Forms
  • WindowsFormsIntegration

3. Add the code to XAML

<Window x:Class="TestWpfApplication.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:math="clr-namespace:MEEL;assembly=MEEL"
        Title="MainWindow" Height="425" Width="626">

    <Grid>
        <WindowsFormsHost Height="350" HorizontalAlignment="Left" Margin="20,12,0,0" Name="windowsFormsHost1" VerticalAlignment="Top" Width="440" >
            <math:MathControl x:Name="mathControl1" ></math:MathControl>
        </WindowsFormsHost>
    </Grid>
</Window>
 

4. Check that license (.licx) is appeared

5. Define MathControl settings via code

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows;
  6. using System.Windows.Controls;
  7. using System.Windows.Data;
  8. using System.Windows.Documents;
  9. using System.Windows.Input;
  10. using System.Windows.Media;
  11. using System.Windows.Media.Imaging;
  12. using System.Windows.Navigation;
  13. using System.Windows.Shapes;
  14. using MEEL;
  15. using MEEL.MathTree;
  16.  
  17. namespace TestWpfApplication
  18. {
  19.     /// <summary>
  20.     /// Interaction logic for MainWindow.xaml
  21.     /// </summary>
  22.     public partial class MainWindow : Window
  23.     {
  24.         public MainWindow()
  25.         {
  26.             InitializeComponent();
  27.  
  28.             #region MathControl settings
  29.             MEEL.MetaData.BaseMathFunctions baseMathFunctions1 = new MEEL.MetaData.BaseMathFunctions();
  30.             MEEL.MetaData.Trigonometry trigonometry1 = new MEEL.MetaData.Trigonometry();
  31.             MEEL.MetaData.Integrals integrals1 = new MEEL.MetaData.Integrals();
  32.             MEEL.MetaData.Exponential exponential1 = new MEEL.MetaData.Exponential();
  33.             //
  34.             // mathControl1
  35.             //
  36.             this.mathControl1.BackColor = System.Drawing.SystemColors.Window;
  37.             baseMathFunctions1.Diff.ImageIndex = 3;
  38.             baseMathFunctions1.Diff.Name = "diff";
  39.             baseMathFunctions1.Diff.ShowInPalette = true;
  40.             baseMathFunctions1.Div.ImageIndex = 5;
  41.             baseMathFunctions1.Div.Name = "div";
  42.             baseMathFunctions1.Div.ShowInPalette = true;
  43.             baseMathFunctions1.Fact.ImageIndex = 10;
  44.             baseMathFunctions1.Fact.Name = "factorial";
  45.             baseMathFunctions1.Fact.ShowInPalette = true;
  46.             baseMathFunctions1.ImageIndex = 7;
  47.             baseMathFunctions1.Max.ImageIndex = 8;
  48.             baseMathFunctions1.Max.Name = "max";
  49.             baseMathFunctions1.Max.ShowInPalette = true;
  50.             baseMathFunctions1.Min.ImageIndex = 9;
  51.             baseMathFunctions1.Min.Name = "min";
  52.             baseMathFunctions1.Min.ShowInPalette = true;
  53.             baseMathFunctions1.Mod.ImageIndex = 11;
  54.             baseMathFunctions1.Mod.Name = "mod";
  55.             baseMathFunctions1.Mod.ShowInPalette = true;
  56.             baseMathFunctions1.Mult.ImageIndex = 4;
  57.             baseMathFunctions1.Mult.Name = "mult";
  58.             baseMathFunctions1.Mult.ShowInPalette = true;
  59.             baseMathFunctions1.Pow.ImageIndex = 6;
  60.             baseMathFunctions1.Pow.Name = "pow";
  61.             baseMathFunctions1.Pow.ShowInPalette = true;
  62.             baseMathFunctions1.Sqrt.ImageIndex = 7;
  63.             baseMathFunctions1.Sqrt.Name = "sqrt";
  64.             baseMathFunctions1.Sqrt.ShowInPalette = true;
  65.             baseMathFunctions1.Summ.ImageIndex = 2;
  66.             baseMathFunctions1.Summ.Name = "summ";
  67.             baseMathFunctions1.Summ.ShowInPalette = true;
  68.             trigonometry1.Cos.ImageIndex = 13;
  69.             trigonometry1.Cos.Name = "cos";
  70.             trigonometry1.Cos.ShowInPalette = true;
  71.             trigonometry1.Ctg.ImageIndex = 15;
  72.             trigonometry1.Ctg.Name = "ctg";
  73.             trigonometry1.Ctg.ShowInPalette = true;
  74.             trigonometry1.ImageIndex = 12;
  75.             trigonometry1.Sin.ImageIndex = 12;
  76.             trigonometry1.Sin.Name = "sin";
  77.             trigonometry1.Sin.ShowInPalette = true;
  78.             trigonometry1.Tg.ImageIndex = 14;
  79.             trigonometry1.Tg.Name = "tg";
  80.             trigonometry1.Tg.ShowInPalette = true;
  81.             integrals1.ImageIndex = 16;
  82.             integrals1.IndefiniteIntegral.ImageIndex = 17;
  83.             integrals1.IndefiniteIntegral.Name = "indefiniteIntegral";
  84.             integrals1.IndefiniteIntegral.ShowInPalette = true;
  85.             integrals1.Integral.ImageIndex = 16;
  86.             integrals1.Integral.Name = "integral";
  87.             integrals1.Integral.ShowInPalette = true;
  88.             exponential1.Exp.ImageIndex = 18;
  89.             exponential1.Exp.Name = "exp";
  90.             exponential1.Exp.ShowInPalette = true;
  91.             exponential1.ImageIndex = 18;
  92.             exponential1.Ln.ImageIndex = 19;
  93.             exponential1.Ln.Name = "ln";
  94.             exponential1.Ln.ShowInPalette = true;
  95.             exponential1.Log.ImageIndex = 20;
  96.             exponential1.Log.Name = "log";
  97.             exponential1.Log.ShowInPalette = true;
  98.             this.mathControl1.ContentMetadata.FunctionDictionary.AddRange(new MEEL.MathTree.MetaData.IFunctionCollection[] {
  99.             baseMathFunctions1,
  100.             trigonometry1,
  101.             integrals1,
  102.             exponential1});
  103.  
  104.            
  105.             this.mathControl1.ContenttDrawOptions.BoundCursorPen.Color = System.Drawing.Color.Salmon;
  106.             this.mathControl1.ContenttDrawOptions.BoundCursorPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  107.             this.mathControl1.ContenttDrawOptions.CursorPen.Color = System.Drawing.Color.Blue;
  108.             this.mathControl1.ContenttDrawOptions.CursorPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
  109.             this.mathControl1.ContenttDrawOptions.CursorPen2.Color = System.Drawing.Color.Green;
  110.             this.mathControl1.ContenttDrawOptions.CursorPen2.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  111.             this.mathControl1.ContenttDrawOptions.DragCursorBound.Color = System.Drawing.Color.LightGray;
  112.             this.mathControl1.ContenttDrawOptions.DragCursorBound.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
  113.             this.mathControl1.ContenttDrawOptions.DragCursorPen.Color = System.Drawing.Color.Gray;
  114.             this.mathControl1.ContenttDrawOptions.DragCursorPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
  115.             this.mathControl1.ContenttDrawOptions.FormulaBrush.Color1 = System.Drawing.Color.Black;
  116.             this.mathControl1.ContenttDrawOptions.FormulaBrush.Color2 = System.Drawing.Color.Black;
  117.             this.mathControl1.ContenttDrawOptions.FormulsBrushSelected.Color1 = System.Drawing.Color.White;
  118.             this.mathControl1.ContenttDrawOptions.FormulsBrushSelected.Color2 = System.Drawing.Color.White;
  119.             this.mathControl1.ContenttDrawOptions.NullTextBrush.Color1 = System.Drawing.Color.Gray;
  120.             this.mathControl1.ContenttDrawOptions.NullTextBrush.Color2 = System.Drawing.Color.Gray;
  121.             this.mathControl1.ContenttDrawOptions.NullTextFont = new System.Drawing.Font("Microsoft Sans Serif", 17F, System.Drawing.FontStyle.Italic);
  122.             this.mathControl1.ContenttDrawOptions.SelectedBrush.Color1 = System.Drawing.Color.LightBlue;
  123.             this.mathControl1.ContenttDrawOptions.SelectedBrush.Color2 = System.Drawing.Color.LightBlue;
  124.             this.mathControl1.ContenttDrawOptions.TextFont = new System.Drawing.Font("Times New Roman", 17F, System.Drawing.FontStyle.Italic);
  125.             this.mathControl1.Expression = null;
  126.             this.mathControl1.LayoutOptions.Layout = MEEL.LayoutOptions.VerticalLayout.Centor;
  127.             this.mathControl1.LayoutOptions.LeftIndent = 20;
  128.             this.mathControl1.LayoutOptions.LineSpacing = 20;
  129.             this.mathControl1.Location = new System.Drawing.Point(0, 0);
  130.             this.mathControl1.Margin = new System.Windows.Forms.Padding(5);
  131.             this.mathControl1.Name = "mathControl1";
  132.             this.mathControl1.Palette.BackgaundBrush.Color1 = System.Drawing.Color.WhiteSmoke;
  133.             this.mathControl1.Palette.BackgaundBrush.Color2 = System.Drawing.Color.White;
  134.             this.mathControl1.Palette.BorderBrush.Color1 = System.Drawing.Color.White;
  135.             this.mathControl1.Palette.BorderBrush.Color2 = System.Drawing.Color.WhiteSmoke;
  136.             this.mathControl1.Size = new System.Drawing.Size(350, 440);
  137.             this.mathControl1.TabIndex = 0;
  138.             #endregion
  139.         }
  140.     }
  141. }
  142.  

6. Done!