2017-02-13 95 views
1

我想添加超鏈接到RichTextBox,然後在單擊鏈接時導航到另一個窗口。RichTextBox中的WPF超鏈接單擊事件

這是我有:

// 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) 
{ 
    ... 
} 

當我運行應用程序,顯示超鏈接,但是當我點擊它沒有任何反應。 link_click方法永遠不會到達。

回答

2

richTextBox.IsDocumentEnabled = true 

按住Ctrl鍵關鍵並單擊超鏈接。它應該工作。如果您不想按住Ctrl鍵,請參閱this post