Version

Overview of List Calculator

ListCalculator

The ListCalculator component allows you to perform calculations on a series of data.

The ListCalculator exposes the ItemsSource and Items properties as well as two collections. One collection contains ItemCalculations which are applied separately to each item in the list. The other is a collection of ListCalculations which is applied across all items in the list.

The xamCalculationManager control can perform calculations using the ListCalculator values by accessing the ReferenceId properties.

ListCalculator control properties chart

The table below explains the properties of the ItemCalculator and lists their default settings.

Property Type Description Default Value

This property specifies the calculations that are performed across a single item in the list.

null

IList

This property specifies the collection of items on which calculations are performed.

null

IEnumerable

This property returns/sets an enumerable that is used to populate the Items collection.

null

This property specifies the calculations that are done across all items of the list.

This read-only property returns a dictionary result containing the results of the list calculations.

null

This property specifies the CalculationManager that will be used to perform the calculations.

null

String

List of properties of an item to exclude calculations being performed on them.

null

String

List of properties of an item to allow calculations to be performed on them.

null

IValueConverter

This property specifies the converter to use to convert the value of the source item to the value that is used in the calculation network.

null

ListCalculation sub-control properties chart

The table below explains the properties of the ListCalculation and lists their default settings.

Property Type Description Default Value

String

This property specifies the formula that will be used to calculate a value for the item.

null

String

This property specifies the id that identifies the item calculation to the calculation network.

null

Code Example: Using List Calculator

Example description

The example below demonstrates how to create calculations using the ListCalculator.

The following code snippet uses the ListCalculator to bind shipping details. Formulas are then defined using the ListCalculation component. The results of the formulas are accessed in two ways:

The first TextBlock binds its Text property to the ListCalcutor’s ListResults dictionary.

The xamCalculationManager accesses the ListCalculation’s ReferenceId and performs calculations using the ReferenceId.

In XAML:

<StackPanel Name="stackPanel">
   <StackPanel.Resources>
      <ig:XamCalculationManager x:Key="CalcManager">
      </ig:XamCalculationManager>
   </StackPanel.Resources>
   <!--bind to a data source -->
   <ig:ListCalculatorElement x:Name="listCalcElement"
                             CalculationManager="{StaticResource CalcManager}"
                             ItemsSource="{Binding Path=AllShippingDetails}">
      <ig:ListCalculatorElement.Calculator>
         <ig:ListCalculator ReferenceId="AllShippingDetailsCalculator">
            <!--ItemCalculations will be applied for each OrderDetail in the list -->
            <ig:ListCalculator.ItemCalculations>
               <ig:ItemCalculation TargetProperty="Shipping"
                                   Formula="([Price] * [Quantity])"/>
               <ig:ItemCalculation ReferenceId="Total"
                                   Formula="([Price] * [Quantity]) + [Shipping]"/>
            </ig:ListCalculator.ItemCalculations>
            <!--ListCalculations will be performed once across all
               OrderDetails in the list -->
            <ig:ListCalculator.ListCalculations>
               <ig:ListCalculation ReferenceId="GrandTotal" Formula="Sum([Total])"/>
            </ig:ListCalculator.ListCalculations>
         </ig:ListCalculator>
      </ig:ListCalculatorElement.Calculator>
   </ig:ListCalculatorElement>
<!--This Text Block binds its Text property to the calculator’s ListResults dictionary.-->
   <TextBlock Text="Results from List Result”/>
   <TextBlock x:Name="Result1" Text="{Binding ElementName=listCalcElement, Path=Calculator.ListResults[GrandTotal].Value}"/>
<!--This Text Block uses the ListCalculators ReferenceID to pick up with GrandTotal by setting a formula -->
   <TextBlock Text="Results from Reference ID”/>
   <TextBlock x:Name="Result2" ig:XamCalculationManager.CalculationManager="{StaticResource CalcManager}">
      <ig:XamCalculationManager.ControlSettings>
         <ig:ControlCalculationSettings Formula="[AllShippingDetailsCalculator/GrandTotal]" />
      </ig:XamCalculationManager.ControlSettings>
   </TextBlock>
</StackPanel>