1

I'm programming a little Twitter Client just for fun. I have the tweet's text on a TextBlock and I want to make the URLs clickable.

I know that I have to parse the URLs with a regexp but... how I put text plus link on the TextBlock?

I can't have a string like: Hello check my blog at <Hyperlink>http​://myblogurl.com</Hyperlink> because the TextBlock doesn't parse the tags.

Then, how I can have a TextBlock that maybe has a link or maybe not?

Thank you.

Dave Clemmer
  • 3,741
  • 12
  • 49
  • 72
Jesus Rodriguez
  • 11,918
  • 9
  • 64
  • 88
  • Did you read this question? http://stackoverflow.com/questions/861409/wpf-making-hyperlinks-clickable/867455#867455 – Ragepotato Dec 15 '09 at 22:58

4 Answers4

3
<RichTextBox  IsDocumentEnabled="True">
        <FlowDocument>
          <Paragraph>
          This is a richTextBox. And this is a <Hyperlink NavigateUri="http://www.microsoft.com">Hyperlink</Hyperlink>.
          </Paragraph>
        </FlowDocument>
  </RichTextBox>

MSDN discussion

Ragepotato
  • 1,630
  • 11
  • 13
1

Rather than use a TextBlock, take a look at using the WPF version of the RichTextBox. It's a very flexible little critter.

Pete OHanlon
  • 9,086
  • 2
  • 29
  • 28
1

Something like...

<TextBlock>
    <Hyperlink Name="btnOpen" Click="btnOpen_Click">
        <TextBlock Text="Click to Open" />
    </Hyperlink>
</TextBlock>
Daniel
  • 2,744
  • 1
  • 31
  • 41
0

You could parse the string in code behind and build up a collection of content controls, change your textblock to a wrap panel and set the children of the panel to your collection you have created.

Daniel
  • 2,744
  • 1
  • 31
  • 41