My problem is to find the urls from the text content and convert it into the clickable hyperlinks via data binding.
This is what I've tried
<TextBlock Tag="{Binding message}" x:Name="postDescription" TextWrapping="Wrap"
Grid.Row="3" Grid.ColumnSpan="3" Margin="10,10,10,12" FontSize="16"
TextAlignment="Justify" Foreground="{StaticResource foreGroundWhite}" >
<Run Text="{Binding description, Converter={StaticResource statusFormatter}}" />
</TextBlock>
In code,
public class StatusFormatter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
return returnTextWithUrl((String)value);
}
public static String returnTextWithUrl(String text)
{
if(text == null) { return null; }
MatchCollection mactches = uriFindRegex.Matches(text);
foreach (Match match in mactches)
{
//Need Help here
HyperlinkButton hyperlink = new HyperlinkButton();
hyperlink.Content = match.Value;
hyperlink.NavigateUri = new Uri(match.Value);
text = text.Replace(match.Value, ??);
}
return text;
}
}
}
The output should be something like this
<TextBlock Tag="{Binding message}" x:Name="postDescription" TextWrapping="Wrap"
Grid.Row="3" Grid.ColumnSpan="3" Margin="10,10,10,12" FontSize="16"
TextAlignment="Justify" Foreground="{StaticResource foreGroundWhite}" >
Click this link -
<Hyperlink NavigateUri="http://www.bing.com">bing</Hyperlink>
- for more info.
</TextBlock>
Any Help?