How to create Multivalue converter in WPF?
We create Multivalue converter when target is associated with multiple source. Let's take an example, I want to display text as a combination of Unit & Value. Then I need to Create a multivalue converter that combines Value & Unit.
Please check below the code for the multivalue converter so you can easily understand it.
Please check below the code for the multivalue converter so you can easily understand it.
public class NumericalTextConverter : IMultiValueConverter { public object Convert( object[] values, Type targetType, object parameter, CultureInfo culture) { string rType = ""; if (values.Count() == 2) { try { var ValueText = (string)values[0]??""; var UnitText = (string)values[1]??""; if (ValueText.Trim() != string.Empty) { rType = ValueText.Trim() + " " + UnitText.Trim(); } } catch { } } return rType; } public object[] ConvertBack( object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotSupportedException(); } }
0 comments :
Post a Comment