开发者

How to remove the hypelink from WPF RichTextbox at runtime?

I have a WPF RichTextBox and using FlowDocument I have added a Paragraph. Inside that Paragraph I have also added multiple Hyperlinks.

I want to remove the hyperlinks at runtime and replace them with some text. All hyperlinks share the same event handlers, so I think I should write the hyperlink removal code inside the hyperlink click event handler.

How can I remove that particular hyperlinks from 开发者_如何学JAVAthe Paragraph which is clicked?


I know it's too late, but I found a much simpler way to remove a hyperlink :

Hyperlink hyperlink = sender as HyperLink;
// we make a selection from BEFORE the hyperlink to AFTER the hyperlink
rtb.Selection.Select(hyperlink.ElementStart, hyperlink.ElementEnd);
// we replace the hyperlink element by a simple text
rtb.Selection.Text = rtb.Selection.Text;

It works pretty well for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜