You can display summaries for a field using XAML or procedural code without the end user selecting a summary calculator from the summary selection dialog box. In order to display a summary for a field, you have to add SummaryDefinition objects to a field layout’s SummaryDefinitions collection. There is a one-to-one relationship between a SummaryDefinition object and a summary value in a field. If you want multiple summary values for a field, you have to add a separate SummaryDefinition for each summary value. For example, if you want the average, sum, and count for two fields in xamDataPresenter™, you have to add six separate SummaryDefinition objects to the field layout’s SummaryDefinitions collection.
Each SummaryDefinition object defines the summary that you want to calculate for a particular field. The two properties of a SummaryDefinition object you must set are the Calculator property and the SourceFieldName property. If you do not set both properties, xamDataPresenter will not display a summary value. You can set the Calculator property to a built-in summary calculator or a custom summary calculator that performs the calculation. You can then set the SourceFieldName property to the name of the field that the calculator uses for values.
The following example code demonstrates how to programmatically add summaries to a field. The example code assumes that you have a field layout with a field named "BasePrice".
...
<igDP:XamDataPresenter Name="xamDataPresenter1">
<igDP:XamDataPresenter.FieldLayouts>
<igDP:FieldLayout>
<igDP:FieldLayout.SummaryDefinitions>
<igDP:SummaryDefinition
Calculator="{x:Static igDP:SummaryCalculator.Average}"
SourceFieldName="BasePrice" />
</igDP:FieldLayout.SummaryDefinitions>
<igDP:FieldLayout.Fields>
<!--TODO: Add Fields to FieldLayout here-->
</igDP:FieldLayout.Fields>
</igDP:FieldLayout>
</igDP:XamDataPresenter.FieldLayouts>
</igDP:XamDataPresenter>
...
Imports Infragistics.Windows.DataPresenter
...
Dim averageCost As New SummaryDefinition()
averageCost.SourceFieldName = "BasePrice"
averageCost.Calculator = SummaryCalculator.Average
Me.xamDataPresenter1.FieldLayouts(0).SummaryDefinitions.Add(averageCost)
...
using Infragistics.Windows.DataPresenter;
...
SummaryDefinition averageCost = new SummaryDefinition();
averageCost.SourceFieldName = "BasePrice";
averageCost.Calculator = SummaryCalculator.Average;
this.xamDataPresenter1.FieldLayouts[0].SummaryDefinitions.Add(averageCost);
...