Skip to content

Commit e932504

Browse files
Kbridge/main/1.7 stable/rich edit box mathmode (#5338)
* snapshot * added math mode detail
1 parent a00410a commit e932504

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

hub/apps/design/controls/rich-edit-box.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
---
2-
description: You can use a RichEditBox control to enter and edit rich text documents that contain formatted text, hyperlinks, and images. You can make a RichEditBox read-only by setting its IsReadOnly property to true.
2+
description: You can use a RichEditBox control to enter and edit rich text documents that contain formatted text, hyperlinks, images, and math equations. You can make a RichEditBox read-only by setting its IsReadOnly property to true.
33
title: RichEditBox
44
ms.assetid: 4AFC0DFA-3B89-434D-9F86-4309CCFF7839
55
label: Rich edit box
66
template: detail.hbs
7-
ms.date: 02/26/2025
7+
ms.date: 04/11/2025
88
ms.topic: article
99
doc-status: Published
1010
ms.localizationpriority: medium
1111
---
12+
1213
# Rich edit box
1314

14-
You can use a RichEditBox control to enter and edit rich text documents that contain formatted text, hyperlinks, and images. You can make a RichEditBox read-only by setting its IsReadOnly property to **true**.
15+
You can use a **RichEditBox** control to enter and edit rich text documents that contain formatted text, hyperlinks, and images, and math equations. You can make a RichEditBox read-only by setting its IsReadOnly property to **true**.
1516

1617
## Is this the right control?
1718

18-
Use a **RichEditBox** to display and edit text files. You don't use a RichEditBox to get user input into you app the way you use other standard text input boxes. Rather, you use it to work with text files that are separate from your app. You typically save text entered into a RichEditBox to a .rtf file.
19+
Use a RichEditBox to display and edit text files. You don't use a RichEditBox to get user input into you app the way you use other standard text input boxes. Rather, you use it to work with text files that are separate from your app. You typically save text entered into a RichEditBox to a .rtf file.
1920

2021
- If the primary purpose of the multi-line text box is for creating read-only documents (such as blog entries or the contents of an email message), and those documents require rich text, use a [rich text block](./rich-text-block.md) instead.
2122
- When capturing text that will only be consumed and not redisplayed to users, use a plain text input control.
@@ -38,7 +39,7 @@ This rich edit box has a rich text document open in it. The formatting and file
3839

3940
![A rich text box with an open document](images/rich-edit-box.png)
4041

41-
## Create a rich edit box
42+
### Create a rich edit box
4243

4344
> [!div class="checklist"]
4445
>
@@ -191,6 +192,26 @@ private void UnderlineButton_Click(object sender, RoutedEventArgs e)
191192
}
192193
```
193194

195+
### Use a rich edit box for math equations
196+
197+
The RichEditBox can display and edit math equations using [UnicodeMath](https://www.unicode.org/notes/tn28/UTN28-PlainTextMath-v3.1.pdf). The equations are stored and retrieved in [MathML 3.0](https://www.w3.org/Math/) format.
198+
199+
By default, the RichEditBox control does not interpret input as math. To enable math mode, call [SetMathMode](/windows/windows-app-sdk/api/winrt/microsoft.ui.text.richedittextdocument.setmathmode) on the [TextDocument](/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.richeditbox.textdocument) property, passing the value [RichEditMathMode.MathOnly](/windows/windows-app-sdk/api/winrt/microsoft.ui.text.richeditmathmode) (to disable math mode, call [SetMathMode](/windows/windows-app-sdk/api/winrt/microsoft.ui.text.richedittextdocument.setmathmode) but pass in the value [NoMath](/windows/windows-app-sdk/api/winrt/microsoft.ui.text.richeditmathmode)).
200+
201+
```csharp
202+
richEditBox.TextDocument.SetMathMode(Microsoft.UI.Text.RichEditMathMode.MathOnly);
203+
```
204+
205+
This enables UnicodeMath input to be automatically recognized and converted to MathML in real time. For example, entering 4^2 converts to 4<sup>2</sup>, and 1/2 converts to ½. See the [WinUI 3 Gallery app](https://apps.microsoft.com/detail/9p3jfpwwdzrc) for more examples.
206+
207+
To save the math content of a rich edit box as a MathML string, call [GetMathML](/windows/windows-app-sdk/api/winrt/microsoft.ui.text.richedittextdocument.getmathml).
208+
209+
``` csharp
210+
richEditBox.TextDocument.GetMathML(out String mathML);
211+
```
212+
213+
To set the math content of a rich edit box, call [SetMathML](/windows/windows-app-sdk/api/winrt/microsoft.ui.text.richedittextdocument.setmathml), passing in a MathML string.
214+
194215
## Choose the right keyboard for your text control
195216

196217
To help users to enter data using the touch keyboard, or Soft Input Panel (SIP), you can set the input scope of the text control to match the kind of data the user is expected to enter. The default keyboard layout is usually appropriate for working with rich text documents.

0 commit comments

Comments
 (0)