c# - WPF RichTextBox get selected element -
i adding hyperlink richtexteditor (link). want hyperlink when user selects hyperlink. , here meant want hyperlink element not text.
what i'm trying create pop-up google docs hyperlink. can add hyperlink fine. need modify existing link. getting display text easy address of link tricky. , don't want whole paragraph , link because there can multiple links in 1 paragraph.
i tried richtextbox.selection.start.getadjacentelement(forward/backward) it's not returning hyperlink. there way selected element/hyperlink?
maybe, helps here ^^
based on reference, try find navigateuri
public static hyperlink gethyberlink(this textpointer pointer) { if (pointer == null) { return null; } inline parent = pointer.parent inline; while (parent != null && !(parent hyperlink)) { parent = parent.parent inline; } return parent == null ? null : (hyperlink)parent; } using:
hyperlink hyperlink = richtextbox.selection.start.gethyberlink(); textrange textrange = new textrange(hyperlink.elementstart, hyperlink.elementend); textrange.applypropertyvalue(textelement.foregroundproperty, brushes.red); result: navigateuri marked red.
Comments
Post a Comment