Skip to content

Latest commit

 

History

History
198 lines (131 loc) · 10.4 KB

File metadata and controls

198 lines (131 loc) · 10.4 KB
layout post
title Customization in .NET MAUI Rich Text Editor | Syncfusion®
description Learn here all about customization support in the Syncfusion® .NET MAUI Rich Text Editor (SfRichTextEditor) control, including the toolbar, and more.
platform maui
control Rich Text Editor
documentation ug

Customization in .NET MAUI Rich Text Editor (SfRichTextEditor)

The .NET MAUI Rich Text Editor control provides extensive options for customizing its appearance and functionality, from the toolbar and editor area to programmatic formatting and hyperlink management.

Customizing Editor Appearance

The SfRichTextEditor provides several properties to customize the appearance of the main editor area, including its background, border, and text wrapping behavior.

  • EditorBackgroundColor: Sets the background color of the content area.
  • BorderColor: Sets the color of the border around the editor control.
  • BorderThickness: Sets the thickness of the border.
  • EnableWordWrap: Specifies whether text should wrap when it reaches the edge of the editor. By default, this is True.

{% tabs %} {% highlight xaml %}

<rte:SfRichTextEditor EditorBackgroundColor="LightYellow" BorderColor="SlateGray" BorderThickness="2" EnableWordWrap="True" />

{% endhighlight %} {% highlight c# %}

SfRichTextEditor richTextEditor = new SfRichTextEditor(); richTextEditor.EditorBackgroundColor = Colors.LightYellow; richTextEditor.BorderColor = Colors.SlateGray; richTextEditor.BorderThickness = 2; richTextEditor.EnableWordWrap = true;

{% endhighlight %} {% endtabs %}

.NET MAUI Customizing Rich Text Editor

Programmatic Formatting

The SfRichTextEditor provides a comprehensive set of methods to apply formatting programmatically. These methods are useful when you want to create your own custom UI for formatting or apply styles dynamically without relying on the built-in toolbar.

The following code examples assume you have an instance of SfRichTextEditor named richTextEditor.

Toggling Character Formatting

You can easily toggle common text styles like bold, italic, and underline on the current text selection.

{% tabs %} {% highlight c# %}

// Toggle bold on the selected text richTextEditor.ToggleBold();

// Toggle italic on the selected text richTextEditor.ToggleItalic();

// Toggle underline on the selected text richTextEditor.ToggleUnderline();

{% endhighlight %} {% endtabs %}

Toggling List Formatting

You can format the selected paragraphs as a bulleted or numbered list.

{% tabs %} {% highlight c# %}

// Apply or remove a bulleted list from the current paragraph richTextEditor.ToggleBulletList();

// Apply or remove a numbered list from the current paragraph richTextEditor.ToggleNumberList();

{% endhighlight %} {% endtabs %}

Applying Text Alignment

These methods allow you to set the text alignment for the selected paragraphs.

{% tabs %} {% highlight c# %}

// Justify the text in the current paragraph richTextEditor.AlignJustify();

// Align the text to the right richTextEditor.AlignRight();

{% endhighlight %} {% endtabs %}

Applying Specific Styles

These methods apply a specific value for a given formatting attribute to the current selection.

{% tabs %} {% highlight c# %}

// Apply a new font family and size richTextEditor.ApplyFontFamily("Arial"); richTextEditor.ApplyFontSize(18);

// Apply a text color and highlight color richTextEditor.ApplyTextColor(Colors.Blue); richTextEditor.ApplyHighlightColor(Colors.Yellow);

// Format the current paragraph as a heading 1 richTextEditor.ApplyParagraphFormat(RichTextEditorParagraphFormat.Heading1);

{% endhighlight %} {% endtabs %}

Managing Hyperlinks

The SfRichTextEditor allows you to programmatically insert, edit, and remove hyperlinks from the content.

Insert a Hyperlink

Use the InsertHyperlink(string displayText, string Url) method to add a new hyperlink at the current cursor position or over the selected text.

  • displayText: The text to be displayed for the hyperlink.
  • Url: The URL the hyperlink will point to.

{% tabs %} {% highlight c# %}

// Insert a new hyperlink richTextEditor.InsertHyperlink("Example", "https://example.com");

{% endhighlight %} {% endtabs %}

Edit a Hyperlink

Use the EditHyperlink(string text, string oldUrl, string newUrl) method to modify an existing hyperlink. You can change its target URL.

  • text: The existing display text for the hyperlink.
  • oldUrl: The original URL of the hyperlink you want to edit.
  • newUrl: The new URL for the hyperlink.

{% tabs %} {% highlight c# %}

// Change the URL of an existing hyperlink richTextEditor.InsertHyperlink("Example", "https://example.com", "https://www.google.com/");

{% endhighlight %} {% endtabs %}

Remove a Hyperlink

Use the RemoveHyperlink(string text, string Url) method to remove a hyperlink from the document. The link's text will remain in place as plain text.

  • text: The display text of the hyperlink to remove.
  • Url: The URL of the hyperlink to remove.

{% tabs %} {% highlight c# %}

// Remove a specific hyperlink, keeping its text richTextEditor.RemoveHyperlink("Example", "https://www.google.com/");

{% endhighlight %} {% endtabs %}