Click or drag to resize

AggregatingMultiValueConverter Class

A converter that aggregates the inner converters for all values, overcoming the restriction of .Net that IMultiValueConverter can't be nested.
Inheritance Hierarchy

Namespace:  TomsToolbox.Wpf.Converters
Assembly:  TomsToolbox.Wpf (in TomsToolbox.Wpf.dll)
Syntax
[ContentPropertyAttribute("Converters")]
public class AggregatingMultiValueConverter : MultiValueConverter

The AggregatingMultiValueConverter type exposes the following members.

Constructors
  NameDescription
Public methodAggregatingMultiValueConverter
Initializes a new instance of the AggregatingMultiValueConverter class
Top
Properties
  NameDescription
Public propertyConverters
Gets the aggregating converters. Must be all IValueConverter, only the last might be a IMultiValueConverter.
Top
Methods
  NameDescription
Protected methodConvert
Converts a value.
(Overrides MultiValueConverterConvert(Object, Type, Object, CultureInfo).)
Protected methodConvertBack
Converts a value.
(Inherited from MultiValueConverter.)
Public methodProvideValue
When implemented in a derived class, returns an object that is provided as the value of the target property for this markup extension.
(Inherited from MultiValueConverter.)
Top
Extension Methods
Remarks
This converter aggregates the result by calling each of the Converters with the aggregated value as input and the next value as parameter, i.e. the first converter will aggregate value[0] and value[1], the second converter will aggregate the result of the first and value[2], etc.

If there are less converters than parameters-1, and the last converter is an IValueConverter, the last converter is used to aggregate the remainder of values.

If there are less converters than parameters-1, and the last converter is an IMultiValueConverter, the IMultiValueConverter is invoked with the aggregated value and all remaining values.

Examples
XAML
<Window.Resources>
  <toms:CompositeMultiValueConverter  x:Key="ThresholdConverter">
    <toms:CompositeMultiValueConverter.MultiValueConverter>
      <toms:AggregatingMultiValueConverter>
        <toms:BinaryOperationConverter Operation="Subtraction"/>
        <toms:BinaryOperationConverter Operation="LessThanOrEqual"/>
      </toms:AggregatingMultiValueConverter>
    </toms:CompositeMultiValueConverter.MultiValueConverter>
    <toms:BooleanToVisibilityConverter/>
  </toms:CompositeMultiValueConverter>
</Window.Resources>
<TextBlock Text="The elapsed time is less than the minimum required time!">
  <TextBlock.Visibility>
    <MultiBinding Converter="{StaticResource ThresholdConverter}">
        <Binding Path="Now" Source="{x:Static toms:DateTimeSource.Default}"/>
        <Binding Path="OperationStartTime"/>
        <Binding Path="MinimumOperationTime"/>
    </MultiBinding>
  </TextBlock.Visibility>
</TextBlock>
See Also