5

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#.

AndreasB
  • 578
  • 4
  • 16

3 Answers3

0

Relatively easy, in C#:

  1. 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?)
  2. Wrap the URL in an <a> tag and point the href to the URL
  3. Replace the original URL in the tweet with the composed anchor tag
Community
  • 1
  • 1
eouw0o83hf
  • 9,438
  • 5
  • 53
  • 75
0

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:

WPF - Making hyperlinks clickable

Community
  • 1
  • 1
andreycha
  • 383
  • 4
  • 22
0

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.

sinelaw
  • 16,205
  • 3
  • 49
  • 80