Skip to content

Commit 015feb5

Browse files
Merge branch 'development' of https://github.com/syncfusion-content/maui-docs into DataFormSmartPasteAISample
2 parents b6c9dfd + b1e2061 commit 015feb5

File tree

11 files changed

+573
-77
lines changed

11 files changed

+573
-77
lines changed

MAUI/Rich-Text-Editor/Basic-Features.md

Lines changed: 225 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,50 @@ documentation: ug
1111

1212
This section covers the essential properties, methods, and events of the .NET MAUI `SfRichTextEditor` for handling content and user interactions.
1313

14-
## Handling Content
14+
## Setting Text
1515

16-
### Setting and Getting HTML Content
16+
The Rich Text Editor control displays the text/formatted text(HTML string) that can be set using the `Text` property.
1717

18-
The rich content of the editor, including all formatting, is accessible through the `Text` property. You can use this property to both load and retrieve the content as an HTML string.
18+
{% tabs %}
1919

20-
{% tabs %}
21-
22-
{% highlight xaml %}
20+
{% highlight xaml %}
2321

24-
<rte:SfRichTextEditor Text="The Syncfusion .NET MAUI Rich Text Editor is a WYSIWYG editor for creating and editing rich text content." />
22+
<richtexteditor:SfRichTextEditor Text= "The &lt;b&gt; rich text editor &lt;/b&gt; component is WYSIWYG editor that provides the best user experience to create and update the content" />
2523

2624
{% endhighlight %}
2725

28-
{% highlight c# %}
26+
{% highlight C# %}
2927

3028
SfRichTextEditor richTextEditor = new SfRichTextEditor();
31-
richTextEditor.Text = "The Syncfusion .NET MAUI Rich Text Editor is a WYSIWYG editor for creating and editing rich text content.";
32-
this.Content = richTextEditor;
29+
richtexteditor.Text = "The <b>rich text editor</b> component is WYSIWYG editor that provides the best user experience to create and update the content";
3330

3431
{% endhighlight %}
3532

3633
{% endtabs %}
3734

38-
### Getting HTML Content Asynchronously
35+
## Retrieving HTML text
3936

40-
To ensure you get the most up-to-date content, especially after recent edits, you can retrieve the HTML string asynchronously using the `GetHtmlString` method.
37+
The formatted text of Rich Text Editor can be retrieved using the `HtmlText` property of `SfRichTextEditor`.
4138

42-
{% tabs %}
39+
{% tabs %}
4340

44-
{% highlight c# %}
41+
{% highlight xaml %}
4542

46-
string htmlContent = await rte.GetHtmlText();
43+
<richtexteditor:SfRichTextEditor HtmlText="The rich text editor component is WYSIWYG editor that provides the best user experience to create and update the content" />
44+
45+
{% endhighlight %}
46+
47+
{% highlight C# %}
48+
49+
SfRichTextEditor richTextEditor = new SfRichTextEditor();
50+
richtexteditor.HtmlText = "The rich text editor component is WYSIWYG editor that provides the best user experience to create and update the content";
4751

4852
{% endhighlight %}
4953

5054
{% endtabs %}
5155

5256

53-
### Getting Selected HTML
57+
## Getting Selected HTML
5458

5559
To retrieve the HTML representation of the currently selected content, use the `GetSelectedText` method.
5660

@@ -64,57 +68,189 @@ string selectedText = await rte.GetSelectedText();
6468

6569
{% endtabs %}
6670

71+
## Default Text Style
72+
73+
You can define the default appearance for any new text typed into the editor. These settings apply to text that does not have any other specific formatting applied.
74+
75+
* `DefaultFontFamily`: Sets the default font family for the content.
76+
* `DefaultFontSize`: Sets the default font size.
77+
* `DefaultTextColor`: Sets the default color of the text.
78+
79+
{% tabs %}
80+
{% highlight xaml %}
81+
82+
<rte:SfRichTextEditor DefaultFontFamily="Impact"
83+
DefaultFontSize="14"
84+
DefaultTextColor="DarkGreen" />
85+
86+
{% endhighlight %}
87+
{% highlight c# %}
88+
89+
SfRichTextEditor richTextEditor = new SfRichTextEditor();
90+
richTextEditor.DefaultFontFamily = "Impact";
91+
richTextEditor.DefaultFontSize = 14;
92+
richTextEditor.DefaultTextColor = Colors.DarkGreen;
93+
94+
{% endhighlight %}
95+
{% endtabs %}
96+
97+
![.NET MAUI Rich Text Editor with Default text style](images/richtexteditor-text.png)
98+
99+
67100
## Placeholder
68101

69-
The editor can display a placeholder text when the content is empty. This is useful for prompting the user. The placeholder is cleared as soon as the user starts typing.
102+
The editor can display a `placeholder` text when the content is empty. This is useful for prompting the user. The placeholder is cleared as soon as the user starts typing.
103+
104+
* `PlaceholderFontFamily`: Sets the font family of the placeholder text.
105+
* `PlaceholderFontSize`: Sets the font size of the placeholder text.
106+
* `PlaceholderColor`: Sets the color of the placeholder text.
70107

71108
{% tabs %}
72109

73110
{% highlight xaml %}
74111

75-
<rte:SfRichTextEditor Placeholder="Type Here..." />
112+
<rte:SfRichTextEditor Placeholder="Type your content here..."
113+
PlaceholderFontFamily="Impact"
114+
PlaceholderFontSize="24"
115+
PlaceholderColor="Green">
116+
</rte:SfRichTextEditor>
76117

77118
{% endhighlight %}
78119

79120
{% highlight c# %}
80121

81122
SfRichTextEditor richTextEditor = new SfRichTextEditor();
82-
richTextEditor.Placeholder = "Type Here...";
123+
richTextEditor.Placeholder = "Type your content here...";
124+
richTextEditor.PlaceholderFontFamily = "Impact";
125+
richTextEditor.PlaceholderFontSize = 24;
126+
richTextEditor.PlaceholderColor = Colors.Green;
83127

84128
{% endhighlight %}
85-
86129
{% endtabs %}
87130

88131
![.NET MAUI Rich Text Editor with Placeholder](images/richtexteditor-placeholder.png)
89132

90133

91-
## Events
92134

93-
### TextChanged Event
135+
## Programmatic Control
94136

95-
The `TextChanged` event is fired whenever the content in the editor is changed. The event arguments provide the old and new HTML content.
137+
The `SfRichTextEditor` provides several methods to programmatically control its behavior, such as managing focus, history, and cursor position.
138+
139+
### Move Cursor to Start
140+
141+
Moves the cursor to the very beginning of the content in the editor.
96142

97143
{% tabs %}
98144

99-
{% highlight xaml %}
145+
{% highlight c# %}
100146

101-
<rte:SfRichTextEditor TextChanged="OnTextChanged" />
147+
richTextEditor.MoveCursorToStart();
102148

103149
{% endhighlight %}
104150

151+
{% endtabs %}
152+
153+
### Move Cursor to End
154+
155+
Moves the cursor to the very end of the content in the editor.
156+
157+
{% tabs %}
158+
105159
{% highlight c# %}
106160

107-
private void OnTextChanged(object sender, RichTextEditorTextChangedEventArgs e)
108-
{
109-
string oldHtml = e.OldValue;
110-
string newHtml = e.NewValue;
111-
// Logic to execute when the Text changes.
112-
}
161+
richTextEditor.MoveCursorToEnd();
162+
163+
{% endhighlight %}
164+
165+
{% endtabs %}
166+
167+
### Increase Indent
168+
169+
Increases the indentation of the current paragraph or selected paragraphs.
170+
171+
{% tabs %}
172+
173+
{% highlight c# %}
174+
175+
richTextEditor.IncreaseIndent();
176+
177+
{% endhighlight %}
178+
179+
{% endtabs %}
180+
181+
### Decrease Indent
182+
183+
Decreases the indentation of the current paragraph or selected paragraphs.
184+
185+
{% tabs %}
186+
187+
{% highlight c# %}
188+
189+
richTextEditor.DecreaseIndent();
190+
191+
{% endhighlight %}
192+
193+
{% endtabs %}
194+
195+
### Set Focus
196+
197+
Programmatically sets the input focus to the rich text editor.
198+
199+
{% tabs %}
200+
201+
{% highlight c# %}
202+
203+
richTextEditor.Focus();
113204

114205
{% endhighlight %}
115206

116207
{% endtabs %}
117208

209+
### Remove Focus
210+
211+
Programmatically removes the input focus from the rich text editor.
212+
213+
{% tabs %}
214+
215+
{% highlight c# %}
216+
217+
richTextEditor.Unfocus();
218+
219+
{% endhighlight %}
220+
221+
{% endtabs %}
222+
223+
### Undo Last Action
224+
225+
Reverts the last action performed in the editor.
226+
227+
{% tabs %}
228+
229+
{% highlight c# %}
230+
231+
richTextEditor.Undo();
232+
233+
{% endhighlight %}
234+
235+
{% endtabs %}
236+
237+
### Redo Last Action
238+
239+
Re-applies the last action that was undone.
240+
241+
{% tabs %}
242+
243+
244+
{% highlight c# %}
245+
246+
richTextEditor.Redo();
247+
248+
{% endhighlight %}
249+
250+
{% endtabs %}
251+
252+
## Events
253+
118254
### FormatChanged Event
119255

120256
The `FormatChanged` event is Occurs when the formatting status changes. This is useful for implementing contextual formatting options.
@@ -131,7 +267,7 @@ The `FormatChanged` event is Occurs when the formatting status changes. This is
131267

132268
private void OnFormatChanged(object sender, RichTextEditorFormatChangedEventArgs e)
133269
{
134-
// Logic to execute when the Format changes.
270+
// Handle when format changed
135271
}
136272

137273
{% endhighlight %}
@@ -161,26 +297,75 @@ private void OnHyperlinkClicked(object sender, RichTextEditorHyperlinkClickedEve
161297
{
162298
string url = e.URL;
163299
string text = e.DisplayText;
164-
// You can handle the navigation here, for example:
300+
// Handle when hyperlink clicked
165301
}
166302

167303
{% endhighlight %}
168304

169305
{% endtabs %}
170306

171-
## Focus Management
307+
### TextChanged Event
172308

173-
You can programmatically set or remove focus from the editor control using the `Focus()` and `Unfocus()` methods.
309+
The `TextChanged` event is fired whenever the content in the editor is changed. The event arguments provide the old and new HTML content.
174310

175311
{% tabs %}
176312

177-
{% highlight C# %}
313+
{% highlight xaml %}
178314

179-
// To set focus on the Rich Text Editor
180-
richTextEditor.Focus();
315+
<rte:SfRichTextEditor TextChanged="OnTextChanged" />
181316

182-
// To remove focus from the Rich Text Editor
183-
richTextEditor.Unfocus();
317+
{% endhighlight %}
318+
319+
{% highlight c# %}
320+
321+
private void OnTextChanged(object sender, RichTextEditorTextChangedEventArgs e)
322+
{
323+
string oldHtml = e.OldValue;
324+
string newHtml = e.NewValue;
325+
// Handle when Text changed
326+
}
184327

328+
{% endhighlight %}
329+
330+
{% endtabs %}
331+
332+
333+
### Focused Event
334+
335+
The `Focused` event occurs when the Rich Text Editor receives input focus.
336+
337+
{% tabs %}
338+
339+
{% highlight xaml %}
340+
<rte:SfRichTextEditor Focused="OnEditorFocused" />
341+
{% endhighlight %}
342+
343+
{% highlight c# %}
344+
richTextEditor.Focused += OnEditorFocused;
345+
346+
private void OnEditorFocused(object sender, EventArgs e)
347+
{
348+
// Handle when editor focused
349+
}
350+
{% endhighlight %}
351+
{% endtabs %}
352+
353+
### Unfocused Event
354+
355+
The `Unfocused` event occurs when the Rich Text Editor loses input focus.
356+
357+
{% tabs %}
358+
359+
{% highlight xaml %}
360+
<rte:SfRichTextEditor Unfocused="OnEditorUnfocused" />
361+
{% endhighlight %}
362+
363+
{% highlight c# %}
364+
richTextEditor.Unfocused += OnEditorUnfocused;
365+
366+
private void OnEditorUnfocused(object sender, EventArgs e)
367+
{
368+
// Handle when editor loses focus
369+
}
185370
{% endhighlight %}
186371
{% endtabs %}

0 commit comments

Comments
 (0)