Skip to content

Latest commit

 

History

History
78 lines (49 loc) · 4.29 KB

hyperlink-support.md

File metadata and controls

78 lines (49 loc) · 4.29 KB
title page_title description position slug
Hyperlink Support
.NET MAUI RichTextEditor Documentation - Hyperlink Support
Review the hyperlink support documentation article for Telerik RichTextEditor for .NET MAUI control.
3
richtexteditor-hyperlink-support

Hyperlink Support

The [.NET MAUI RichTextEditor]({%slug richtexteditor-overview%}) provides built-in support for creating and managing hyperlinks. Through the exposed commands related to hyperlinks, namely ApplyHyperlinkCommand, RemoveHyperlinkCommand, and OpenHyperlinkCommand, users can manipulate the hyperlinks inside the RichTextEditor content.

In addition, RichTextEditorToolbar exposes predefined toolbar items wired to the hyperlink commands.

  • RichTextEditorAddHyperlinkToolbarItem—Opens a popup to enter URL information and executes an action that adds a hyperlink for the current selection.
  • RichTextEditorAddOrEditHyperlinkToolbarItem—Opens a popup to enter URL information and executes an action that adds or edits a hyperlink for the current selection.
  • RichTextEditorHyperlinkNavigationToolbarItem—This toolbar item adds or edits hyperlinks depending whether a hyperlink is selected. If a hyperlink is selected, the editor navigates to toolbar sub-items for operations related to a hyperlink. If a hyperlink is not selected, a popup with a dialog is displayed to enter URL information and add a hyperlink for the current selection.

Additional Toolbar Items for Hyperlink Operations

The RichTextEditorHyperlinkNavigationToolbarItem has the following items:

  • RichTextEditorEditHyperlinkToolbarItem—Edits the hyperlink from the current selection.
  • RichTextEditorRemoveHyperlinkToolbarItem—Removes the hyperlink from the current selection.
  • RichTextEditorOpenHyperlinkToolbarItem—Navigates to the URL.

.NET MAUI RichTextEditor Hyperlink Navigation

The next image shows the RichTextEditorEditHyperlinkToolbarItem on mobile platforms:

.NET MAUI RichTextEditor Hyperlink Navigation

For more details, see the [RichTextEditor Toolbar]({%slug richtexteditor-toolbar%}#predefined-toolbar-items) topic.

Methods

You can also take advantage of the following API related to hyperlinks:

  • GetHyperlinkAsync method—Asynchronously returns a RichTextHyperlink under the caret in the editor (or null if no hyperlink is present). The RichTextHyperlink object contains the Url and Title of the link.

Hyperlink Error Handling

In case users try to open invalid URLs (for example, the URL is not absolute, the domain does not exist or is incomplete, and so on), the following message is shown by default and indicates that the URL has an error:

.NET MAUI RichTextEditor Hyperlink Error Handling

You can override the default behavior by handling the RichTextEditor's OpenHyperlinkError event:

  • OpenHyperlinkError event—Raised when users try to open invalid URLs in the editor. The OpenHyperlinkError event handler receives two parameters:

    • The Sender which is the RichTextEditor control.
    • OpenHyperlinkErrorEventArgs provides the following properties:
      • Error—of type System.Exception, can be used to get the exact error message.
      • Url—of type string, defining the URL of the hyperlink.
      • Handled—boolean property indicating whether the event is handled.

To change the default error handling behavior:

  1. Subscribe to the event.
  2. Set the Handled property of the event arguments to True to prevent the default message.
  3. Add a custom implementation.

The following example demonstrates how to use the OpenHyperlinkError event:

The next snippet shows the event handler which shows a custom message:

For a runnable example with the RichTextEditor Hyperlink Error Handling, see the [SDKBrowser Demo Application]({%slug sdkbrowser-app%}) and go to RichTextEditor > Events.

See Also

  • [Commands]({%slug richtexteditor-commands%})
  • [Configure the RichTextEditor]({%slug richtexteditor-configuration%})
  • [Events]({%slug richtexteditor-events%})
  • [Working with images]({%slug richtexteditor-images-overview%})