Eutherpy
Eutherpy

Reputation: 4571

WPF hyperlink in RichTextBox click event

I want to add a hyperlink to a RichTextBox, then navigate to another window when the link is clicked.

This is what I have:

 // Add paragraphs to the FlowDocument
 Hyperlink link = new Hyperlink();
 link.IsEnabled = true;
 Paragraph paragraph = new Paragraph();
 myFlowDoc.Blocks.Add(paragraph);
 link.Inlines.Add(reviewAuthor);
 link.Click += new RoutedEventHandler(this.link_Click);
 paragraph.Inlines.Add(link);
 richTextBox.Document = myFlowDoc;

 protected void link_Click(object sender, RoutedEventArgs e)
 {
     ...
 }

When I run the application, the hyperlink is displayed, but nothing happens when I click on it. The link_click method is never reached.

Upvotes: 1

Views: 1982

Answers (1)

rmojab63
rmojab63

Reputation: 3631

Set

 richTextBox.IsDocumentEnabled = true 

hold down Ctrl key and Click on the Hyperlink. It should work.

See this post if you don't like to hold the Ctrl down.

Upvotes: 2

Related Questions