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
  System.Windows.MarkupMarkupExtension
    TomsToolbox.Wpf.ConvertersMultiValueConverter
      TomsToolbox.Wpf.ConvertersAggregatingMultiValueConverter

Namespace: TomsToolbox.Wpf.Converters
Assembly: TomsToolbox.Wpf (in TomsToolbox.Wpf.dll) Version: 2.21.0+44d18b541fc9419ec3c549350a832394661b2a4d
XMLNS for XAML: Not mapped to an xmlns.
Syntax
[ContentPropertyAttribute("Converters")]
public class AggregatingMultiValueConverter : MultiValueConverter

The AggregatingMultiValueConverter type exposes the following members.

Constructors
 NameDescription
Public methodAggregatingMultiValueConverterInitializes 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
 NameDescription
Public Extension MethodSafeCastT Performs a cast from object to T, avoiding possible null violations if T is a value type.
(Defined by ObjectExtensions)
Top
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.

Example
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