New to Telerik UI for .NET MAUI? Start a free 30-day trial

Hyperlink Support

RichTextEditor 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.

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 topic.


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.

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:

<telerik:RadRichTextEditor x:Name="richTextEditor" 
                           Grid.Row="{OnIdiom Desktop=1, Phone=0}" />

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

private void RichTextEditor_OpenHyperlinkError(object sender, OpenHyperlinkErrorEventArgs e)
    e.Handled = true;
    Application.Current.MainPage.DisplayAlert(string.Format("Error opening {0}", e.Url), e.Error.Message, "Ok");

For a runnable example with the RichTextEditor Hyperlink Error Handling, see the SDKBrowser Demo Application and go to RichTextEditor > Events.

See Also

In this article