Skip to content

Commit 7e7d6fc

Browse files
authored
Merge pull request #3566 from syncfusion-content/Tools-UG-Rich-text-editor
Prepared UG for .NET Maui SfRichTextEditor
2 parents b92997a + 6191332 commit 7e7d6fc

14 files changed

+922
-0
lines changed

MAUI/Rich-Text-Editor/AutoSize.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
layout: post
3+
title: AutoSize in .NET MAUI Rich Text Editor control | Syncfusion®
4+
description: Learn here all about AutoSize support in Syncfusion® .NET MAUI Rich Text Editor (SfRichTextEditor) control and more.
5+
platform: maui
6+
control: Rich Text Editor
7+
documentation: ug
8+
---
9+
10+
# AutoSize in .NET MAUI Rich Text Editor (SfRichTextEditor)
11+
12+
The .NET MAUI Rich Text Editor control supports dynamically changing its height based on the content. This feature can be enabled by setting the `EnableAutoSize` property to `True`. When enabled, the editor will automatically resize to fit its content, eliminating the need for scroll bars within the control. By default, the `EnableAutoSize` property is `False`.
13+
14+
The following code example shows how to enable `EnableAutoSize` in the Rich Text Editor control.
15+
16+
{% tabs %}
17+
18+
{% highlight xaml %}
19+
20+
<rte:SfRichTextEditor EnableAutoSize="True" />
21+
22+
{% endhighlight %}
23+
24+
{% highlight c# %}
25+
26+
SfRichTextEditor richTextEditor = new SfRichTextEditor();
27+
richTextEditor.EnableAutoSize = true;
28+
29+
{% endhighlight %}
30+
{% endtabs %}
31+
32+
When `EnableAutoSize` is active, the editor’s height will grow or shrink as content is added or removed.
33+
34+
![.NET MAUI Rich Text Editor with AutoSize enabled](images/richtexteditor-autosize.gif)
35+
36+
N> When using `EnableAutoSize`, it is recommended not to set the `HeightRequest` property on the `SfRichTextEditor`, as this may interfere with the automatic resizing behavior. For the best results, place the editor within a layout that can accommodate its changing height, such as a `VerticalStackLayout` inside a `ScrollView`.
37+
38+
The following example demonstrates how to place an auto-sizing `SfRichTextEditor` within a `ScrollView`.
39+
40+
{% tabs %}
41+
{% highlight xaml %}
42+
<ScrollView>
43+
<VerticalStackLayout>
44+
<Label Text="User Feedback" FontSize="Title" Padding="10"/>
45+
<rte:SfRichTextEditor x:Name="richTextEditor"
46+
EnableAutoSize="True"
47+
Placeholder="Please provide your detailed feedback here..."/>
48+
<Button Text="Submit" Margin="10"/>
49+
</VerticalStackLayout>
50+
</ScrollView>
51+
{% endhighlight %}
52+
{% endtabs %}
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
---
2+
layout: post
3+
title: Basic Features in .NET MAUI Rich Text Editor | Syncfusion®
4+
description: Learn about the basic features of the .NET MAUI Rich Text Editor (SfRichTextEditor) such as handling content, events, and other core functionalities.
5+
platform: maui
6+
control: Rich Text Editor
7+
documentation: ug
8+
---
9+
10+
# Basic Features in .NET MAUI Rich Text Editor (SfRichTextEditor)
11+
12+
This section covers the essential properties, methods, and events of the .NET MAUI `SfRichTextEditor` for handling content and user interactions.
13+
14+
## Handling Content
15+
16+
### Setting and Getting HTML Content
17+
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.
19+
20+
{% tabs %}
21+
22+
{% highlight xaml %}
23+
24+
<rte:SfRichTextEditor Text="The Syncfusion .NET MAUI Rich Text Editor is a WYSIWYG editor for creating and editing rich text content." />
25+
26+
{% endhighlight %}
27+
28+
{% highlight c# %}
29+
30+
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;
33+
34+
{% endhighlight %}
35+
36+
{% endtabs %}
37+
38+
### Getting HTML Content Asynchronously
39+
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.
41+
42+
{% tabs %}
43+
44+
{% highlight c# %}
45+
46+
string htmlContent = await rte.GetHtmlText();
47+
48+
{% endhighlight %}
49+
50+
{% endtabs %}
51+
52+
53+
### Getting Selected HTML
54+
55+
To retrieve the HTML representation of the currently selected content, use the `GetSelectedText` method.
56+
57+
{% tabs %}
58+
59+
{% highlight c# %}
60+
61+
string selectedText = await rte.GetSelectedText();
62+
63+
{% endhighlight %}
64+
65+
{% endtabs %}
66+
67+
## Placeholder
68+
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.
70+
71+
{% tabs %}
72+
73+
{% highlight xaml %}
74+
75+
<rte:SfRichTextEditor Placeholder="Enter your content here..." />
76+
77+
{% endhighlight %}
78+
79+
{% highlight c# %}
80+
81+
SfRichTextEditor richTextEditor = new SfRichTextEditor();
82+
richTextEditor.Placeholder = "Enter your content here...";
83+
84+
{% endhighlight %}
85+
86+
{% endtabs %}
87+
88+
![.NET MAUI Rich Text Editor with Placeholder](images/richtexteditor-image.png)
89+
90+
91+
## Events
92+
93+
### TextChanged Event
94+
95+
The `TextChanged` event is fired whenever the content in the editor is changed. The event arguments provide the old and new HTML content.
96+
97+
{% tabs %}
98+
99+
{% highlight xaml %}
100+
101+
<rte:SfRichTextEditor TextChanged="OnTextChanged" />
102+
103+
{% endhighlight %}
104+
105+
{% highlight c# %}
106+
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+
}
113+
114+
{% endhighlight %}
115+
116+
{% endtabs %}
117+
118+
### FormatChanged Event
119+
120+
The `FormatChanged` event is Occurs when the formatting status changes. This is useful for implementing contextual formatting options.
121+
122+
{% tabs %}
123+
124+
{% highlight xaml %}
125+
126+
<rte:SfRichTextEditor FormatChanged="OnFormatChanged" />
127+
128+
{% endhighlight %}
129+
130+
{% highlight c# %}
131+
132+
private void OnFormatChanged(object sender, RichTextEditorFormatChangedEventArgs e)
133+
{
134+
// Logic to execute when the Format changes.
135+
}
136+
137+
{% endhighlight %}
138+
139+
{% endtabs %}
140+
141+
### HyperlinkClicked Event
142+
143+
The `HyperlinkClicked` event is fired when a user taps on a hyperlink within the content. The event arguments contain the URL and the text of the Clicked link.
144+
145+
{% tabs %}
146+
147+
{% highlight xaml %}
148+
149+
<rte:SfRichTextEditor HyperlinkClicked="OnHyperlinkClicked"/>
150+
151+
{% endhighlight %}
152+
153+
{% highlight c# %}
154+
155+
SfRichTextEditor richTextEditor = new SfRichTextEditor();
156+
richTextEditor.Text = "<p>Visit the <a href='https://www.syncfusion.com'>Syncfusion</a> website.</p>";
157+
richTextEditorHyperlinkClicked += OnHyperlinkClicked
158+
159+
160+
private void OnHyperlinkClicked(object sender, RichTextEditorHyperlinkClickedEventArgs e)
161+
{
162+
string url = e.URL;
163+
string text = e.DisplayText;
164+
// You can handle the navigation here, for example:
165+
}
166+
167+
{% endhighlight %}
168+
169+
{% endtabs %}
170+
171+
## Focus Management
172+
173+
You can programmatically set or remove focus from the editor control using the `Focus()` and `Unfocus()` methods.
174+
175+
{% tabs %}
176+
177+
{% highlight C# %}
178+
179+
// To set focus on the Rich Text Editor
180+
richTextEditor.Focus();
181+
182+
// To remove focus from the Rich Text Editor
183+
richTextEditor.Unfocus();
184+
185+
{% endhighlight %}
186+
{% endtabs %}

0 commit comments

Comments
 (0)