I've got an application that shows a list of messages that are shown as a TextBox:
<TextBox Text="{Binding ., Converter={StaticResource MessageTextConverter}}"
BorderThickness="0"
Background="Transparent"
IsReadOnly="True"
FontSize="14"
TextWrapping="Wrap"
VerticalAlignment="Stretch"/>
Those messages may or may not contain a link or an email. So what I needed was a way to dynamically check the text for any links and emails and set the Hyperlinks in the TextBox.
I searched online and could not find a similar case. Which is the best way to do this? Using a regex?
EDIT:
Some people marked this as duplicated of C# WPF Text with links , but this question is about showing a hyperlink and making it clickable. I already knew about this and how to use it. My question is, what is the best way to check a random text for a link or an email and mark it.
Example of entries o text:
Entry 1: "Some text before url http://www.google.com"
Entry 2: "http://www.google.com some text that has nothing to do with url"
Entry 3: "Some text before url http://www.google.com some text after url"
Entry 4: "Some text before urls http://www.google.com some text between urls http://www.google.com some text after urls"
In resume, given a random text that may contain an url in the middle, what is the best way to separate that chunk of url and highlight it? Using a regex? Or is there another way to do this in wpf that is easier?