I have this code
<Hyperlink NavigateUri="">
<Run>
<Run.Text>
<MultiBinding StringFormat="{}{0}{1}{2}">
<Binding Path="Text" ElementName="tbxHostData" />
<Binding Path="Text" ElementName="tbxWebSiteDataName" />
<Binding Path="Text" ElementName="tbxDataServicesName" />
</MultiBinding>
</Run.Text>
</Run>
</Hyperlink>
How I can use <MultiBinding> to populate NavigateUri=""?
Is it possible at all?
Thanks to @ThomasLevesque !
SOLUTION:
<Window.Resources>
<c:StringToUriConverter x:Key="stringToUriConverter"/>
</Window.Resources>
<Hyperlink.NavigateUri>
<MultiBinding ConverterParameter="" Converter="{StaticResource uriConverter}">
<Binding Path="Text" ElementName="tbxHostData" />
<Binding Path="Text" ElementName="tbxWebSiteDataName" />
<Binding Path="Text" ElementName="tbxDataServicesName" />
</MultiBinding>
</Hyperlink.NavigateUri>
C#
[ValueConversion(typeof(String), typeof(Uri))]
public class UriConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
Uri result;
string input = String.Join(string.Empty, values);
Uri.TryCreate(input, UriKind.RelativeOrAbsolute, out result);
return result;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
It is possible, but not with
StringFormat(which works only for properties of typeString). You need to use a converter instead.