WPF RichTextBox how to get it to accept clickable urls
Loading
WPF RichTextBox how to get it to accept clickable urls
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Raghunath BhukanPosted Jan 21, 2026, 11:45 AM
If you want a WPF
RichTextBoxwhere URLs in the text are automatically clickable links. By default,RichTextBoxjust treats text as plain content orFlowDocumentcontent — it won’t automatically make URLs clickable. You have to either detect URLs and convert them toHyperlinkelements, or handle mouse clicks manually.Here’s how to do it step by step.
Step 1: Use a
RichTextBoxwith aFlowDocumentImportant:
IsDocumentEnabled="True"allowsHyperlinkelements inside theRichTextBoxto be clickable.Step 2: Add text with URLs and convert them to
HyperlinkprogrammaticallyStep 3: Explanation
IsDocumentEnabled = trueis crucial for hyperlinks to work.The Regex detects URLs in the text.
Each URL is replaced with a
Hyperlinkelement.RequestNavigateevent handles the click and opens the URL in the default browser.Non-URL text is added as a normal
Runelement.Optional Enhancements
Automatically detect URLs while typing: Attach a
TextChangedhandler and re-parse the text to add hyperlinks.Styling hyperlinks: You can set
Foregroundcolor, underline style, etc.Support email links: Extend the regex to include
mailto:.