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
SystemObject
  TomsToolbox.Wpf.ConvertersMultiValueConverter
    TomsToolbox.Wpf.ConvertersAggregatingMultiValueConverter

Namespace:  TomsToolbox.Wpf.Converters
Assembly:  TomsToolbox.Wpf (in TomsToolbox.Wpf.dll) Version: 1.0.64.0 (1.0.64.0)
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
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>
Contracts
Invariants
_converters != null
Learn more about contracts
See Also