0

I have an IMultiValueConveter on my textblock that can return strings, doubles etc.. In some case the Converter can get a string that that contains an address to a website. I am keeping it simple for test purposes right now where when i get a string that starts with http or https I want to return a hyperlink that is clickable in the UI but I'm not figuring out how to make it work.

 public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            
            var valueOwner = values[0] as ValueOwner;
         
            if (valueOwner.Value is string)
            {
                var valueOwnerstring = valueOwner.Value.ToString();

                if (valueOwnerstring.Contains("https") || valueOwnerstring.Contains("http"))
                {
                    //var run = new Run(valueOwnerstring);
                    //var hyperlink = new Hyperlink(run);
                    //var navigateUri = hyperlink.NavigateUri;
                    // return navigateUri;

                    var uri = new Uri(valueOwnerstring);
                    return uri.AbsoluteUri;
                }
            }
         
            return string.Format("{0} {1}", valueOwner.Value);
        }
Mass
  • 1
  • 5
  • Clickable link is a `...` or any other control, and it is not simply passed as a string. – AgentFire Nov 16 '20 at 10:00
  • You may set the Inlines property of the TextBlock instead of its Text, e.g. with the help of an attached property as shown [here](https://stackoverflow.com/a/636741/1136211). Then return a Hyperlink from the Converter. – Clemens Nov 16 '20 at 10:02
  • Btw `valueOwnerstring.Contains("https")` is not the same as _...string that starts with..._ . Use `valueOwnerstring.StartsWith("https")` instead. – Nawed Nabi Zada Nov 16 '20 at 10:40

0 Answers0