views:

304

answers:

1

How can I retrieve hyperlink url from selection text in WPF Richtextbox?

I select a hyperlink string in wpf richtextbox. How can I retrieve the url hyperlink of the selected text?

I use the snipset code below. But It cannot effect.

TextPointer caretPosition = mainRTB.Selection.Start;

Hyperlink hlEdit = GetHyperlinkAncestor(caretPosition);

private Hyperlink GetHyperlinkAncestor(TextPointer position)
{
    Inline parent = position.Parent as Inline;

    while (parent != null && !(parent is Hyperlink))
    {
        parent = parent.Parent as Inline;
    }
    return parent as Hyperlink;
}
A: 

It is fixed! A fuzzy problem

Sean