Syncfusion AI Assistant

How can I help you?

Events in WPF Markdown Viewer (SfMarkdownViewer)

15 May 20261 minute to read

This section explains how to handle hyperlink interactions in the SfMarkdownViewer using the HyperlinkClicked event.

The HyperlinkClicked event is triggered when a hyperlink in the Markdown content is clicked. It provides access to the clicked URL and allows you to control or cancel the default navigation behavior.

HyperlinkClicked Event

The HyperlinkClicked event provides details about the clicked hyperlink through the MarkdownHyperlinkClickedEventArgs.

This event argument exposes the following properties:

  • Url: Gets the URL of the clicked hyperlink.
  • Cancel: Gets or sets a value indicating whether to cancel the default navigation behavior

You can disable hyperlink navigation by setting the Cancel property of the MarkdownHyperlinkClickedEventArgs to true in the HyperlinkClicked event handler.

// Wires the event handler for `HyperlinkClicked` event.    
markdownViewer.HyperlinkClicked += MarkdownViewer_HyperlinkClicked;

private void MarkdownViewer_HyperlinkClicked(object? sender, MarkdownHyperlinkClickedEventArgs args)
{
    // Gets or sets the value to handle the navigation of hyperlink.
    args.Cancel = true;
}

Retrieve the Clicked URL

You can retrieve the URL of the clicked hyperlink by accessing the Url property of the event arguments.

// Wires the event handler for `HyperlinkClicked` event.    
markdownViewer.HyperlinkClicked += MarkdownViewer_HyperlinkClicked;

private void MarkdownViewer_HyperlinkClicked(object? sender, MarkdownHyperlinkClickedEventArgs args)
{
    //Returns the URL clicked in the Markdown viewer control.
    string URL = args.Url;
}