从C#Richtextbox中的数据库加载后处理超链接单击事件
我将Richtextbox的文档添加到数据库中。文档有多个超链接。通过编程方式添加到此richtextbox的每个超链接如下:从C#Richtextbox中的数据库加载后处理超链接单击事件,c#,wpf,hyperlink,richtextbox,rtf,C#,Wpf,Hyperlink,Richtextbox,Rtf,我将Richtextbox的文档添加到数据库中。文档有多个超链接。通过编程方式添加到此richtextbox的每个超链接如下: RichTextBox.IsDocumentEnabled = true; RichTextBox.IsReadOnly = true; Run run = new Run(RichTextBox.Selection.Text); Hyperlink hyp = new Hyperlink(run);
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中的单击事件。
请帮忙。所以我找到了解决办法。我只在richtextbox中添加以下代码
<RichTextBox.Resources>
<Style TargetType="Hyperlink">
<Setter Property="Cursor" Value="Hand" />
<EventSetter Event="Click" Handler="hyperLink_Click" />
</Style>
</RichTextBox.Resources>
当然不能,您认为代理必须保存在哪里?@Spawn,我只测试它。你还有别的解决办法吗?