如何检测在 WPF 应用程序的 RichTextBox 中写入或粘贴的 URL

问题描述:

有时用户会在聊天应用程序中聊天时输入网站 URL.我需要让 RichTextBox 自动检测这些 URL,但我不知道如何.通用文本框不检测 URL,所以我用 RichTextBox 代替.我知道 RichTextBoxes 可以检测 URL,但我不知道如何检测.有人可以建议我怎么做吗?

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?

正如 schoola 所指出的,WPF RichTextBox 不会自动检测 URL.但是 本文描述了可用于此目的的自定义 RichTextBox 的一个相当简单(150 行)的实现.

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.