Back to Devexpress

TreeListView.CustomSummaryCommand Property

wpf-devexpress-dot-xpf-dot-grid-dot-treelistview-8558e83c.md

latest5.9 KB
Original Source

TreeListView.CustomSummaryCommand Property

Gets or sets a command that calculates a custom summary.

Namespace : DevExpress.Xpf.Grid

Assembly : DevExpress.Xpf.Grid.v25.2.dll

NuGet Package : DevExpress.Wpf.Grid.Core

Declaration

csharp
public ICommand<NodeSummaryArgs> CustomSummaryCommand { get; set; }
vb
Public Property CustomSummaryCommand As ICommand(Of NodeSummaryArgs)

Property Value

TypeDescription
ICommand<NodeSummaryArgs>

A command that calculates a custom summary.

|

Remarks

Bind a command to the CustomSummaryCommand property to maintain a clean MVVM pattern. The command works like a CustomSummary event handler and allows you to specify custom summaries in a View Model.

Total summaries contain predefined aggregate functions. These functions allow you to calculate the following:

  • The number of data rows ( Count )
  • The maximum and minimum values ( Max and Min )
  • The sum and the average value ( Sum and Average )

Use the CustomSummaryCommand property to apply custom rules to calculate summaries. This property allows you to implement custom aggregate functions or use a custom algorithm to calculate summary values.

To calculate a summary manually:

  1. Create a summary item and set its SummaryItemBase.SummaryType property to Custom.
  2. Create a command that uses a custom algorithm to calculate summary values.
  3. Assign this command to the CustomSummaryCommand property.

Refer to the following help topic for more information: Custom Summary.

Example

The following example demonstrates how to calculate custom node summaries in the TreeListView. To do this, create a command and bind it to the TreeListView’s CustomSummaryCommand property. Use the IsNodeSummary property to determine whether to calculate node summaries.

View Example: How to calculate custom Node Summaries in TreeListView

xaml
<dxg:TreeListControl AutoGenerateColumns="AddNew" ItemsSource="{Binding Employees}">
    <dxg:TreeListControl.View>
        <dxg:TreeListView AutoExpandAllNodes="True" AutoWidth="True" 
                          KeyFieldName="ID" ParentFieldName="ParentID" 
                          ShowNodeFooters="True" 
                          CustomSummaryCommand="{Binding CustomSummaryCommand}">
            <dxg:TreeListView.NodeSummary>
                <dxg:TreeListSummaryItem FieldName="Statistics" SummaryType="Custom"/>
            </dxg:TreeListView.NodeSummary>
        </dxg:TreeListView>
    </dxg:TreeListControl.View>
</dxg:TreeListControl>
cs
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.Mvvm.Xpf;
// ...
    class MainViewModel : ViewModelBase {
    // ...
        [Command]
        public void CustomSummaryCommand(NodeSummaryArgs args) {
            if(args.IsNodeSummary && args.SummaryItem.PropertyName == nameof(Employee.Statistics)) {
                if(args.SummaryProcess == SummaryProcess.Calculate) {
                    args.TotalValue = Convert.ToDouble(args.TotalValue) + (double)args.FieldValue;
                }
            }
        }
        // ...
    }
vb
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.DataAnnotations
Imports DevExpress.Mvvm.Xpf
' ...
    Friend Class MainViewModel
        Inherits ViewModelBase
        ' ...
        <Command>
        Public Sub CustomSummaryCommand(ByVal args As NodeSummaryArgs)
            If args.IsNodeSummary AndAlso Equals(args.SummaryItem.PropertyName, NameOf(Employee.Statistics)) Then
                If args.SummaryProcess = SummaryProcess.Calculate Then
                    args.TotalValue = Convert.ToDouble(args.TotalValue) + CDbl(args.FieldValue)
                End If
            End If
        End Sub
        ' ...
    End Class

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the CustomSummaryCommand property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

wpf-tree-list-calculate-custom-node-summaries/CS/CustomNodeSummaries_MVVM/MainWindow.xaml#L19

xml
ShowNodeFooters="True"
              CustomSummaryCommand="{Binding CustomSummaryCommand}">
<dxg:TreeListView.NodeSummary>

See Also

TreeListView Class

TreeListView Members

DevExpress.Xpf.Grid Namespace