It’s always been a problem for the developers of Windows Phone applications that they are unable to write mathematical equations on Windows Phone when they are building applications for mathematics. Especially beginners encounter many problems doing it.
How can you write a mathematical equation? How can you view as it is?
Here is a simple way of doing it.
Let us have the following equation:
I have a text block in XAML of my application that is “MathTB” , now in C# code I will write my equation.
Here I have used Unicode to display the super script \u00B2 to display the super script in Windows Phone in a text block.
In other cases you may use a rich text block to perform different properties and layouts of the text.
These may be:
- Ø Bold Text
- Ø Underlined Text
- Ø Hyperlink
- Ø Colored and Black text at same time
- Ø Italics and Bold at same time
And many more you can use as in the following:
- MathTB.Text = "(x + 1)";
-
- MathTB.Text += String.Format(" {0,-3}", '\u00B2');
-
- MathTB.Text += " = ";
-
- MathTB.Text += "x";
-
- MathTB.Text += String.Format(" {0,-3}", '\u00B2');
-
- MathTB.Text += " + ";
-
- MathTB.Text += "2x + 1";
In this case I have programmatically displayed a rich text box and applied a few features to it.
- Paragraph prgParagraph = new Paragraph();
-
-
-
- Bold bldText = new Bold();
-
- bldText.Inlines.Add(new Run() { Text = "(x + 1)" });
-
- Italic itlText = new Italic();
-
- itlText.Inlines.Add(new Run() { Text = String.Format(" {0,-3}", '\u00B2'), Foreground = new SolidColorBrush(Colors.Yellow) });
-
- Underline unText = new Underline();
-
- unText.Inlines.Add(new Run() { Text = "This is some example text, underlined" });
-
-
- Bold bldTextWithItalic = new Bold();
-
- bldTextWithItalic.Inlines.Add(new Italic()
- {
-
- Inlines = { new Run()
-
- { Text = "This is some example text, bold and italic" } }
-
- });
-
- prgParagraph.Inlines.Add(bldText);
-
- prgParagraph.Inlines.Add(itlText);
-
- prgParagraph.Inlines.Add(new LineBreak());
-
- prgParagraph.Inlines.Add(unText);
-
- prgParagraph.Inlines.Add(new LineBreak());
-
- prgParagraph.Inlines.Add(bldTextWithItalic);
-
- rbtMyRichTextBox.Blocks.Add(prgParagraph);
Note: You can change the color of the text if you want by using SolidColorBrush(Colors.~your color~).
That is all you need to do to write a mathematical equation in Windows Phone using a rich textbox or a simple text block.
Happy coding!
Personal Blog: Blend Expression.