Hyperlink Class
A hyperlink in a document.
Namespace: DevExpress.Blazor.RichEdit
Assembly: DevExpress.Blazor.RichEdit.v24.1.dll
NuGet Package: DevExpress.Blazor.RichEdit
Declaration
public class Hyperlink :
DocumentElementBase
Remarks
A hyperlink can navigate to a bookmark in the document or to an external resource.
The BookmarkName property specifies the name of the bookmark to which the hyperlink navigates.
The Url property specifies the external resource’s URL.
If the BookmarkName property is specified, the Url property is not in effect.
Create a Hyperlink
Call a CreateAsync method to add a hyperlink to a sub-document.
<DxRichEdit @bind-Selection="@selection" @ref="@richEdit" />
@code {
DxRichEdit richEdit;
Selection selection;
@* ... *@
/* Surround the code that contains an asynchronous operation with a try-catch block to handle
the OperationCanceledException. This exception is thrown when an asynchronous operation is canceled. */
try {
@* ... *@
// Insert a hyperlink to a URL
var position = richEdit.Selection.CaretPosition;
await documentAPI.Hyperlinks.CreateAsync(position, "Go to Google", "https://www.google.com/");
@* ... *@
}
catch (OperationCanceledException e) {
Console.WriteLine($"{nameof(OperationCanceledException)} thrown with message: {e.Message}");
}
}
Find a Hyperlink
Call the GetAsync(Int32, CancellationToken) method to find a hyperlink with the specified index in the document.
// Gets URLs of all hyperlinks in the document
List<string> hyperlinkUrls = new List<string>();
var hyperlinks = await documentAPI.Hyperlinks.GetAllAsync();
for (int i = 0; i < hyperlinks.Count; i++) {
var hLink = await documentAPI.Hyperlinks.GetAsync(i);
if (hLink.Url != "")
hyperlinkUrls.Add(hLink.Url);
}
Remove a Hyperlink
Call the RemoveAsync(Int32, CancellationToken) method to remove a hyperlink.
// Remove the first hyperlink
await documentAPI.Hyperlinks.RemoveAsync(0);
The Hyperlink Dialog
Users can select one of the following commands to invoke this dialog:
- The Insert → Hyperlink ribbon command
- The Edit Hyperlink… context menu command
- The Hyperlink… context menu command
The Hyperlink dialog allows users to edit existing and create new links to web pages, bookmarks, or e-mail addresses.