errorcode007
errorcode007

Reputation: 331

TextBlock Binding in WPF to display Links

I'm binding a TextBlock to a string through Caliburn.Micro. Now I wan't to automatically detect URLs and display them as a clickable hyperlink.

I've tried doing so in a ValueConverter changing every URL to a Hyperlink. Unfortunately I now have "<Hyperlink..." displayed but no actuall link.

How would I do this?

Upvotes: 0

Views: 701

Answers (2)

NestorArturo
NestorArturo

Reputation: 2516

In that case, you are getting what you are sending. I assume you are binding to the Text property and that's why you are getting plain text.

This is not simple. You must feed the Inlines property which allow you to add formatted text (Run) and Hyperlinks. However this is not a dependency property so a binding is not available.

You might feed this property in code, or, use a behavior which somehow gives you XAML kind of access to that property.

Upvotes: 0

brunnerh
brunnerh

Reputation: 185225

You'll never get this to work with TextBlock.Text, it will always be just plain text. You could bind the Content of a ContentControl and in the converter return a normal TextBlock or a TextBlock containing a Hyperlink

Upvotes: 1

Related Questions