Handling a Click hyperlink event after loading from a database in C # Richtextbox

I am adding a Richtextbox document to the database. The document has several hyperlinks. Each hyperlink added to this richtextbox programmatically looks like this:

        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 the database, I cannot handle the click event in the new Richtextbox. Please, help.

+1
source share
1 answer

So, I find a solution. I add only codes as follows in richtextbox

        <RichTextBox.Resources>
            <Style TargetType="Hyperlink">
                <Setter Property="Cursor" Value="Hand" />
                <EventSetter Event="Click" Handler="hyperLink_Click" />
            </Style>
        </RichTextBox.Resources>
+2
source

All Articles