wpf-devexpress-dot-xpf-dot-grid-dot-gridcontrol-dd061ea7.md
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
public ICommand<RowSummaryArgs> CustomSummaryCommand { get; set; }
Public Property CustomSummaryCommand As ICommand(Of RowSummaryArgs)
| Type | Description |
|---|---|
| ICommand<RowSummaryArgs> |
A command that calculates a custom summary.
|
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 and group summaries contain predefined aggregate functions. These functions allow you to calculate the following:
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:
If the GridControl.View property is set to TreeListView, use the TreeListView.CustomSummaryCommand property.
Note
The CustomSummaryCommand property does not work in Server Mode.
Refer to the following help topic for more information: Custom Summary.
The following code sample calculates the total number of empty cells in the specified column:
View Example: How to Use Custom Summaries
<dxg:GridControl ItemsSource="{Binding Items}"
CustomSummaryCommand="{Binding CustomSummaryCommand}">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Text" GroupIndex="0" />
<dxg:GridColumn FieldName="Number" />
</dxg:GridControl.Columns>
<dxg:GridControl.View>
<dxg:TableView AutoWidth="True"
NavigationStyle="Cell"
TotalSummaryPosition="Bottom" />
</dxg:GridControl.View>
<dxg:GridControl.TotalSummary>
<dxg:GridSummaryItem DisplayFormat="Total empty cells count: {0}"
FieldName="Number"
SummaryType="Custom" />
</dxg:GridControl.TotalSummary>
<dxg:GridControl.GroupSummary>
<dxg:GridSummaryItem DisplayFormat="Group empty cells count: {0}"
FieldName="Number"
SummaryType="Custom" />
</dxg:GridControl.GroupSummary>
</dxg:GridControl>
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.Mvvm.Xpf;
// ...
public class MainViewModel : ViewModelBase {
// ...
[Command]
public void CustomSummary(RowSummaryArgs args) {
if(args.SummaryItem.PropertyName != "Number")
return;
if(args.SummaryProcess == SummaryProcess.Start) {
args.TotalValue = 0;
}
if(args.SummaryProcess == SummaryProcess.Calculate) {
if(IsEmptyCell(args.FieldValue))
args.TotalValue = (int)args.TotalValue + 1;
}
}
bool IsEmptyCell(object fieldValue) {
return !((int?)fieldValue).HasValue;
}
}
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.DataAnnotations
Imports DevExpress.Mvvm.Xpf
' ...
Public Class MainViewModel
Inherits ViewModelBase
' ...
<Command>
Public Sub CustomSummary(ByVal args As RowSummaryArgs)
If Not Equals(args.SummaryItem.PropertyName, "Number") Then Return
If args.SummaryProcess = SummaryProcess.Start Then
args.TotalValue = 0
End If
If args.SummaryProcess = SummaryProcess.Calculate Then
If IsEmptyCell(args.FieldValue) Then args.TotalValue = CInt(args.TotalValue) + 1
End If
End Sub
Private Function IsEmptyCell(ByVal fieldValue As Object) As Boolean
Return Not CType(fieldValue, Integer?).HasValue
End Function
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-data-grid-summarize-empty-cells/CS/CustomSummary_EmptyCells_MVVM/MainWindow.xaml#L13
<dxg:GridControl ItemsSource="{Binding Items}"
CustomSummaryCommand="{Binding CustomSummaryCommand}">
<dxg:GridControl.Columns>
See Also