我将Richtextbox的文档添加到数据库中。文档有几个超链接。每个超链接都通过以编程方式添加到此richtextbox,如下所示:
RichTextBox.IsDocumentEnabled = true;
RichTextBox.IsReadOnly = true;
Run run = new Run(RichTextBox.Selection.Text);
Hyperlink hyp = new Hyperlink(run);
WordMain main = new WordMain();
hyp.Click += new RoutedEventHandler(main.hyperLink_Click);
hyp.NavigateUri = new Uri("http://search.msn.com");
RichTextBox.Cut();
var container = new InlineUIContainer(new TextBlock(hyp), RichTextBox.Selection.Start);
RichTextBox.IsDocumentEnabled = true;
RichTextBox.IsReadOnly = false;
从数据库加载数据后,我无法在新的Richtextbox中处理点击事件。 请帮忙。
答案 0 :(得分:2)
所以我找到了解决方案。我只在richtextbox
中添加以下代码 <RichTextBox.Resources>
<Style TargetType="Hyperlink">
<Setter Property="Cursor" Value="Hand" />
<EventSetter Event="Click" Handler="hyperLink_Click" />
</Style>
</RichTextBox.Resources>