Sarita
Sarita

Reputation: 13

How to detect URLs written or pasted in a RichTextBox in WPF application

Sometimes a user will type a website URL while chatting in a Chat Application. I need to make the RichTextBox detect these URLs automatically, but I do not know how. General TextBox does not detect URLs, so i have used RichTextBox instead. I know RichTextBoxes can detect URLs but I don't know how. Can anybody suggest how I might do this?

Upvotes: 1

Views: 2827

Answers (2)

kmote
kmote

Reputation: 16745

As schoola pointed out, the WPF RichTextBox does not auto-detect URLs. However this article describes a fairly simple (150 line) implementation of a custom RichTextBox that can be used for this very purpose.

Upvotes: 2

schoola
schoola

Reputation: 724

The WPF RichTextBox does not support auto-detection of URLs, but the Windows Forms Rich Text Box does. You might use a WindowsFormsHost element in your WPF application like this:

[...]
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" 
[...]

<WindowsFormsHost >
    <wf:RichTextBox DetectUrls="True" />
</WindowsFormsHost>

Upvotes: 1

Related Questions