I have a problem which I do not know how to solve exactly like I'd like it to be solved. I pull tweets from certain twitter feeds such as users and # (via .rss search). However, some of the tweets contains a link, which isn't click able when it's shown in the ListBox (datatemplate). Is there an easy way to convert everything within each individual tweet which contains "http://<-link->" into an actual click able link? Either via XAML or C#.
3 Answers
Relatively easy, in C#:
- Pull the URL out with a Regex (example regex here: What is the best regular expression to check if a string is a valid URL?)
- Wrap the URL in an
<a>
tag and point thehref
to the URL - Replace the original URL in the tweet with the composed anchor tag

- 1
- 1

- 9,438
- 5
- 53
- 75
-
Hm - I'm not using HTML for this purpose. – AndreasB Jun 08 '13 at 08:37
In case you don't have predefined text (and you don't) you need to parse tweet text to find hyperlink and to replace raw text with hyperlink Run
. See below link for example:
I found the HtmlTextBlock control useful. It is:
A WPF TextBlock that can parse a limited set of HTML tags and display them (originally a project by Leung Yat Chun on CodeProject.com)
The only problem in your case is that the tags are in a different format than true HTML, you have to write them with square brackets ([]
) rather than angle ones (<>
).
The original version of the code on CodeProject is not the latest, I had to do some searching and eventually put it up as a github repository since it is open source (and with the owner's blessing) - as the repo readme mentions, the code is not mine.

- 16,205
- 3
- 49
- 80