Handle Hyperlink Click event after load from Datab

2019-08-12 17:30发布

I add document of Richtextbox to database. Document have several hyperlink. Every hyperlink added to this richtextbox by programmatically as follows:

        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;

After loading data from database I can't handle click event in a new Richtextbox. Please, help.

1条回答
放我归山
2楼-- · 2019-08-12 18:04

So I find solution. I only add codes as follow to richtextbox

        <RichTextBox.Resources>
            <Style TargetType="Hyperlink">
                <Setter Property="Cursor" Value="Hand" />
                <EventSetter Event="Click" Handler="hyperLink_Click" />
            </Style>
        </RichTextBox.Resources>
查看更多
登录 后发表回答