Handle Hyperlink Click event after load from Database in C# Richtextbox
Asked Answered
E

1

1

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.

Eliaseliason answered 6/12, 2015 at 22:0 Comment(2)
Sure you can't, where do you think delegates must be saved?Crosscrosslet
@Spawn, I only test it. Do you have another solution?Eliaseliason
E
2

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>
Eliaseliason answered 6/12, 2015 at 22:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.