Bind text with links to RichTextBox

后端 未结 3 937
野趣味
野趣味 2020-12-06 03:16

I need to bind text which may contain hyperlinks to RichTextBox so it could show text as normal text and links as hyperlinks.

For example I have following text:

3条回答
  •  一整个雨季
    2020-12-06 03:51

    Thanks for the solution!

    One minor modification I made was right at the end, I replaced the check on the count, with a line that just adds a substring of the full text, this way it does not truncate everything after the last URL, all text is retained.

            paragraph.Inlines.Add(text.Substring(textPosition, text.Length - textPosition));
    
            //if (urlMatches.Count == 0)
            //{
            //    paragraph.Inlines.Add(text);
            //}
    

提交回复
热议问题