Skip to content

Commit 0bde8ee

Browse files
authored
Merge pull request #3583 from syncfusion-content/Tools-UG-Rich-text-editor
Updated the missing APIs in SfRichTextEditor UG
2 parents c46d5ae + 2a01f3c commit 0bde8ee

File tree

7 files changed

+403
-76
lines changed

7 files changed

+403
-76
lines changed

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

Lines changed: 218 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,46 +11,43 @@ 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 C# %}
4542

46-
string htmlContent = await rte.GetHtmlText();
43+
string HTMLText = richtexteditor.HtmlText;
4744

4845
{% endhighlight %}
4946

5047
{% endtabs %}
5148

5249

53-
### Getting Selected HTML
50+
## Getting Selected HTML
5451

5552
To retrieve the HTML representation of the currently selected content, use the `GetSelectedText` method.
5653

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

6562
{% endtabs %}
6663

64+
## Default Text Style
65+
66+
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.
67+
68+
* `DefaultFontFamily`: Sets the default font family for the content.
69+
* `DefaultFontSize`: Sets the default font size.
70+
* `DefaultTextColor`: Sets the default color of the text.
71+
72+
{% tabs %}
73+
{% highlight xaml %}
74+
75+
<rte:SfRichTextEditor DefaultFontFamily="Impact"
76+
DefaultFontSize="14"
77+
DefaultTextColor="DarkGreen" />
78+
79+
{% endhighlight %}
80+
{% highlight c# %}
81+
82+
SfRichTextEditor richTextEditor = new SfRichTextEditor();
83+
richTextEditor.DefaultFontFamily = "Impact";
84+
richTextEditor.DefaultFontSize = 14;
85+
richTextEditor.DefaultTextColor = Colors.DarkGreen;
86+
87+
{% endhighlight %}
88+
{% endtabs %}
89+
90+
![.NET MAUI Rich Text Editor with Default text style](images/richtexteditor-text.png)
91+
92+
6793
## Placeholder
6894

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.
95+
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.
96+
97+
* `PlaceholderFontFamily`: Sets the font family of the placeholder text.
98+
* `PlaceholderFontSize`: Sets the font size of the placeholder text.
99+
* `PlaceholderColor`: Sets the color of the placeholder text.
70100

71101
{% tabs %}
72102

73103
{% highlight xaml %}
74104

75-
<rte:SfRichTextEditor Placeholder="Type Here..." />
105+
<rte:SfRichTextEditor Placeholder="Type your content here..."
106+
PlaceholderFontFamily="Impact"
107+
PlaceholderFontSize="24"
108+
PlaceholderColor="Green">
109+
</rte:SfRichTextEditor>
76110

77111
{% endhighlight %}
78112

79113
{% highlight c# %}
80114

81115
SfRichTextEditor richTextEditor = new SfRichTextEditor();
82-
richTextEditor.Placeholder = "Type Here...";
116+
richTextEditor.Placeholder = "Type your content here...";
117+
richTextEditor.PlaceholderFontFamily = "Impact";
118+
richTextEditor.PlaceholderFontSize = 24;
119+
richTextEditor.PlaceholderColor = Colors.Green;
83120

84121
{% endhighlight %}
85-
86122
{% endtabs %}
87123

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

90126

91-
## Events
92127

93-
### TextChanged Event
128+
## Programmatic Control
94129

95-
The `TextChanged` event is fired whenever the content in the editor is changed. The event arguments provide the old and new HTML content.
130+
The `SfRichTextEditor` provides several methods to programmatically control its behavior, such as managing focus, history, and cursor position.
131+
132+
### Move Cursor to Start
133+
134+
Moves the cursor to the very beginning of the content in the editor.
96135

97136
{% tabs %}
98137

99-
{% highlight xaml %}
138+
{% highlight c# %}
100139

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

103142
{% endhighlight %}
104143

144+
{% endtabs %}
145+
146+
### Move Cursor to End
147+
148+
Moves the cursor to the very end of the content in the editor.
149+
150+
{% tabs %}
151+
105152
{% highlight c# %}
106153

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-
}
154+
richTextEditor.MoveCursorToEnd();
155+
156+
{% endhighlight %}
157+
158+
{% endtabs %}
159+
160+
### Increase Indent
161+
162+
Increases the indentation of the current paragraph or selected paragraphs.
163+
164+
{% tabs %}
165+
166+
{% highlight c# %}
167+
168+
richTextEditor.IncreaseIndent();
169+
170+
{% endhighlight %}
171+
172+
{% endtabs %}
173+
174+
### Decrease Indent
175+
176+
Decreases the indentation of the current paragraph or selected paragraphs.
177+
178+
{% tabs %}
179+
180+
{% highlight c# %}
181+
182+
richTextEditor.DecreaseIndent();
183+
184+
{% endhighlight %}
185+
186+
{% endtabs %}
187+
188+
### Set Focus
189+
190+
Programmatically sets the input focus to the rich text editor.
191+
192+
{% tabs %}
193+
194+
{% highlight c# %}
195+
196+
richTextEditor.Focus();
197+
198+
{% endhighlight %}
199+
200+
{% endtabs %}
201+
202+
### Remove Focus
203+
204+
Programmatically removes the input focus from the rich text editor.
205+
206+
{% tabs %}
207+
208+
{% highlight c# %}
209+
210+
richTextEditor.Unfocus();
211+
212+
{% endhighlight %}
213+
214+
{% endtabs %}
215+
216+
### Undo Last Action
217+
218+
Reverts the last action performed in the editor.
219+
220+
{% tabs %}
221+
222+
{% highlight c# %}
223+
224+
richTextEditor.Undo();
225+
226+
{% endhighlight %}
227+
228+
{% endtabs %}
229+
230+
### Redo Last Action
231+
232+
Re-applies the last action that was undone.
233+
234+
{% tabs %}
235+
236+
237+
{% highlight c# %}
238+
239+
richTextEditor.Redo();
113240

114241
{% endhighlight %}
115242

116243
{% endtabs %}
117244

245+
## Events
246+
118247
### FormatChanged Event
119248

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

132261
private void OnFormatChanged(object sender, RichTextEditorFormatChangedEventArgs e)
133262
{
134-
// Logic to execute when the Format changes.
263+
// Handle when format changed
135264
}
136265

137266
{% endhighlight %}
@@ -161,26 +290,75 @@ private void OnHyperlinkClicked(object sender, RichTextEditorHyperlinkClickedEve
161290
{
162291
string url = e.URL;
163292
string text = e.DisplayText;
164-
// You can handle the navigation here, for example:
293+
// Handle when hyperlink clicked
165294
}
166295

167296
{% endhighlight %}
168297

169298
{% endtabs %}
170299

171-
## Focus Management
300+
### TextChanged Event
172301

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

175304
{% tabs %}
176305

177-
{% highlight C# %}
306+
{% highlight xaml %}
178307

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

182-
// To remove focus from the Rich Text Editor
183-
richTextEditor.Unfocus();
310+
{% endhighlight %}
311+
312+
{% highlight c# %}
313+
314+
private void OnTextChanged(object sender, RichTextEditorTextChangedEventArgs e)
315+
{
316+
string oldHtml = e.OldValue;
317+
string newHtml = e.NewValue;
318+
// Handle when Text changed
319+
}
320+
321+
{% endhighlight %}
322+
323+
{% endtabs %}
324+
325+
326+
### Focused Event
327+
328+
The `Focused` event occurs when the Rich Text Editor receives input focus.
329+
330+
{% tabs %}
331+
332+
{% highlight xaml %}
333+
<rte:SfRichTextEditor Focused="OnEditorFocused" />
334+
{% endhighlight %}
335+
336+
{% highlight c# %}
337+
richTextEditor.Focused += OnEditorFocused;
338+
339+
private void OnEditorFocused(object sender, EventArgs e)
340+
{
341+
// Handle when editor focused
342+
}
343+
{% endhighlight %}
344+
{% endtabs %}
345+
346+
### Unfocused Event
184347

348+
The `Unfocused` event occurs when the Rich Text Editor loses input focus.
349+
350+
{% tabs %}
351+
352+
{% highlight xaml %}
353+
<rte:SfRichTextEditor Unfocused="OnEditorUnfocused" />
354+
{% endhighlight %}
355+
356+
{% highlight c# %}
357+
richTextEditor.Unfocused += OnEditorUnfocused;
358+
359+
private void OnEditorUnfocused(object sender, EventArgs e)
360+
{
361+
// Handle when editor loses focus
362+
}
185363
{% endhighlight %}
186364
{% endtabs %}

0 commit comments

Comments
 (0)