Search code examples
c#wpfxamlhyperlinktextblock

Making URLs on a textblock clickable


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.


Solution

  • <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