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.
<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>