tags:

views:

118

answers:

4

Hello, Im 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 link or maybe not?

Thank you.

+1  A: 

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
+2  A: 
<RichTextBox  IsDocumentEnabled="True">
        <FlowDocument>
          <Paragraph>
          This is a richTextBox. And this is a <Hyperlink NavigateUri="http://www.microsoft.com"&gt;Hyperlink&lt;/Hyperlink&gt;.
          </Paragraph>
        </FlowDocument>
  </RichTextBox>

MSDN discussion

Ragepotato
+1  A: 

Something like...

<TextBlock>
    <Hyperlink Name="btnOpen" Click="btnOpen_Click">
        <TextBlock Text="Click to Open" />
    </Hyperlink>
</TextBlock>
Daniel
No, because It's a random string with a random number of url...
Jesus Rodriguez
A: 

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