我有一个WPF RichTextBox,并使用FlowDocument添加了一个Paragraph。在这个Paragraph中,我还添加了多个Hyperlink。
我想在运行时删除超链接,并用一些文本替换它们。所有超链接共享相同的事件处理程序,因此我认为应该在超链接单击事件处理程序中编写删除超链接的代码。
如何从单击的段落中删除特定的超链接?
发布于 2011-07-14 13:11:41
我知道为时已晚,但我找到了一种更简单的方法来删除超链接:
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;它对我来说效果很好。
https://stackoverflow.com/questions/6688532
复制相似问题