public class MultiBindConverter : IMultiValueConverter { #region IMultiValueConverter Members public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (values[0] != null) { if (values[1] != null) { return new Uri(values[1].ToString(), UriKind.RelativeOrAbsolute); } return new Uri(values[0].ToString(), UriKind.RelativeOrAbsolute); } return null; } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) { if (value != null) { var uri = (Uri)value; var uriString = uri.OriginalString; if (uri.OriginalString.Contains(";component/")) { uriString = uriString.Substring(uriString.IndexOf("/") + 1); } return new object[] {uriString, uriString}; } //return Binding.DoNothing; } #endregion IMultiValueConverter Members }
|