I've got a situation in which I need to show an integer value, bound to a property on my data context, after putting it through two separate conversions:
I realise I could do both steps by creating my own converter (that implements IValueConverter). However, I've already got a separate value converter that does just the first step, and the second step is covered by Int32Converter.
Is there a way I can chain these two existing classes in XAML without having to create a further class that aggregates them?
If I need to clarify any of this, please let me know. :)
Thanks.
I used this method by Gareth Evans in my Silverlight project.
Here's my implementation of it:
public class ValueConverterGroup : List<IValueConverter>, IValueConverter
{
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return this.Aggregate(value, (current, converter) => converter.Convert(current, targetType, parameter, culture));
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
#endregion
}
Which can then be used in XAML like this:
<c:ValueConverterGroup x:Key="InvertAndVisibilitate">
<c:BooleanInverterConverter/>
<c:BooleanToVisibilityConverter/>
</c:ValueConverterGroup>