user1036379
user1036379

Reputation: 23

Determine if selected text is Hyperlink in RichTextBox?

I also am hoping to populate a text box with the URL of the selected Hyperlink. I think I am along the right path with this code, but I don't know how to complete it:

        TextPointer position = RichTextBoxEditor.Selection.Start;

        Inline parent = position.Parent as Inline;

        foreach (Hyperlink hl in RichTextBoxEditor.Blocks.OfType<Hyperlink>())
        {

        }

Upvotes: 0

Views: 525

Answers (1)

NestorArturo
NestorArturo

Reputation: 2516

Yes... you are in the right path. Never done before but if your cursor is inside an hyperlink this gives you the hyperlink:

TextPointer position1 = richTextBox1.Selection.Start;
Inline parent = position1.Parent as Inline;
TextPointer position2 = parent.ElementStart;

Hyperlink hl = position2.Parent as Hyperlink;

Upvotes: 1

Related Questions