From f4ca0fedf40833f677ba2c64cd1355db6766e653 Mon Sep 17 00:00:00 2001 From: Sreemon Premkumar M Date: Mon, 18 Aug 2025 18:29:01 +0530 Subject: [PATCH 1/3] ES-975464 - Resolve the ReadMe file length issue in this sample repository --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5a46764..9b1eae8 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # How to define summary rows using AttachedProperty in WPF and UWP DataGrid (SfDataGrid)? -This example illustrates how to define summary rows using AttachedProperty in [WPF DataGrid](https://www.syncfusion.com/wpf-ui-controls/datagrid) (SfDataGrid). +This example illustrates how to define summary rows using [AttachedProperty](https://learn.microsoft.com/en-us/dotnet/desktop/wpf/properties/attached-properties-overview) in [WPF DataGrid](https://www.syncfusion.com/wpf-ui-controls/datagrid) (SfDataGrid). -[WPF DataGrid](https://www.syncfusion.com/wpf-ui-controls/datagrid) (SfDataGrid) provides support to show the column summary. If the DataContext of SfDataGrid is ViewModel, you can bind [SummaryColumns](http://help.syncfusion.com/cr/cref_files/wpf/Syncfusion.SfGrid.WPF~Syncfusion.UI.Xaml.Grid.GridSummaryRow~SummaryColumns.html) to a property in ViewModel using the [AttachedProperty](https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/attached-properties-overview) of type List. +[WPF DataGrid](https://www.syncfusion.com/wpf-ui-controls/datagrid) (SfDataGrid) provides support to show the column summary. If the DataContext of `SfDataGrid` is ViewModel, you can bind [SummaryColumns](http://help.syncfusion.com/cr/cref_files/wpf/Syncfusion.SfGrid.WPF~Syncfusion.UI.Xaml.Grid.GridSummaryRow~SummaryColumns.html) to a property in ViewModel using the [AttachedProperty](https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/attached-properties-overview) of type `List`. + +Refer to the code example in the following KB article to define an `AttachedProperty` of type List. KB article - [How to define summary rows using AttachedProperty in WPF and UWP DataGrid (SfDataGrid)](https://www.syncfusion.com/kb/9838/how-to-define-summary-rows-using-attached-property-in-wpf-datagrid-sfdatagrid) From c33875ea0d5ece6e20139feb153a673c4954fb31 Mon Sep 17 00:00:00 2001 From: Sreemon Premkumar M Date: Mon, 18 Aug 2025 18:31:17 +0530 Subject: [PATCH 2/3] ES-975464 - Highlighted the word --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b1eae8..da231f0 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,6 @@ This example illustrates how to define summary rows using [AttachedProperty](htt [WPF DataGrid](https://www.syncfusion.com/wpf-ui-controls/datagrid) (SfDataGrid) provides support to show the column summary. If the DataContext of `SfDataGrid` is ViewModel, you can bind [SummaryColumns](http://help.syncfusion.com/cr/cref_files/wpf/Syncfusion.SfGrid.WPF~Syncfusion.UI.Xaml.Grid.GridSummaryRow~SummaryColumns.html) to a property in ViewModel using the [AttachedProperty](https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/attached-properties-overview) of type `List`. -Refer to the code example in the following KB article to define an `AttachedProperty` of type List. +Refer to the code example in the following KB article to define an `AttachedProperty` of type `List`. KB article - [How to define summary rows using AttachedProperty in WPF and UWP DataGrid (SfDataGrid)](https://www.syncfusion.com/kb/9838/how-to-define-summary-rows-using-attached-property-in-wpf-datagrid-sfdatagrid) From 84396ae9e75e8c315c95e3692623ba27621e3d2f Mon Sep 17 00:00:00 2001 From: SreemonPremkumarMuthukrishnan Date: Fri, 31 Oct 2025 01:23:24 +0530 Subject: [PATCH 3/3] ES-975464 - Addressed the concern --- README.md | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 103 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index da231f0..a866c32 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,107 @@ -# How to define summary rows using AttachedProperty in WPF and UWP DataGrid (SfDataGrid)? +# How to Define Summary Rows using AttachedProperty in WPF / UWP DataGrid? -This example illustrates how to define summary rows using [AttachedProperty](https://learn.microsoft.com/en-us/dotnet/desktop/wpf/properties/attached-properties-overview) in [WPF DataGrid](https://www.syncfusion.com/wpf-ui-controls/datagrid) (SfDataGrid). +This example illustrates how to define summary rows using [AttachedProperty](https://learn.microsoft.com/en-us/dotnet/desktop/wpf/properties/attached-properties-overview) in [WPF DataGrid](https://www.syncfusion.com/wpf-ui-controls/datagrid) and [UWP DataGrid](https://www.syncfusion.com/uwp-ui-controls/datagrid) (SfDataGrid). -[WPF DataGrid](https://www.syncfusion.com/wpf-ui-controls/datagrid) (SfDataGrid) provides support to show the column summary. If the DataContext of `SfDataGrid` is ViewModel, you can bind [SummaryColumns](http://help.syncfusion.com/cr/cref_files/wpf/Syncfusion.SfGrid.WPF~Syncfusion.UI.Xaml.Grid.GridSummaryRow~SummaryColumns.html) to a property in ViewModel using the [AttachedProperty](https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/attached-properties-overview) of type `List`. +DataGrid provides support to show the column summary. If the DataContext of DataGrid is ViewModel, you can bind [SummaryColumns](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Grid.GridSummaryRow.html#Syncfusion_UI_Xaml_Grid_GridSummaryRow_SummaryColumns) to a property in ViewModel using the AttachedProperty of type List <GridSummaryColumn>. -Refer to the code example in the following KB article to define an `AttachedProperty` of type `List`. +Refer to the following code example to define the AttachedProperty of type List <GridSummaryColumn>. -KB article - [How to define summary rows using AttachedProperty in WPF and UWP DataGrid (SfDataGrid)](https://www.syncfusion.com/kb/9838/how-to-define-summary-rows-using-attached-property-in-wpf-datagrid-sfdatagrid) +#### C# + +``` csharp +public class SfDataGridAttachedProperty +{ + public static readonly DependencyProperty DynamicSummaryColumnsProperty = DependencyProperty.RegisterAttached("DynamicSummaryColumns", + typeof(List), + typeof(SfDataGridAttachedProperty) + , new FrameworkPropertyMetadata(null, OnDynamicSummaryColumnsChanged)); + + public static void SetDynamicSummaryColumns(UIElement element, List value) + { + element.SetValue(DynamicSummaryColumnsProperty, value); + } + public static List GetDynamicSummaryColumns(UIElement element) + { + return (List)element.GetValue(DynamicSummaryColumnsProperty); + } + + private static void OnDynamicSummaryColumnsChanged(DependencyObject d, DependencyPropertyChangedEventArgs args) + { + SfDataGrid grid = d as SfDataGrid; + + if (grid.TableSummaryRows.Count() > 1) + { + grid.TableSummaryRows.Clear(); + } + + GridTableSummaryRow gsr = new GridTableSummaryRow(); + gsr.ShowSummaryInRow = false; + + var list = ((List)args.NewValue); + + foreach (var item in list) + { + gsr.SummaryColumns.Add(item); + } + + grid.TableSummaryRows.Add(gsr); + } +} +``` + +Refer to the following code example to populate GridSummaryColumn in Viewmodel. + +#### C# + +``` csharp +internal class ViewModel : INotifyPropertyChanged +{ + private List _summarycols; + + public List SummaryColumns + { + get { return _summarycols; } + set + { + _summarycols = value; + RaisePropertyChanged("SummaryColumns"); + } + } + + public ViewModel() + { + PopulateEmployeeDetails(); + SetSummaryColumns(); + } + + private void SetSummaryColumns() + { + SummaryColumns = new List(); + SummaryColumns.Add(new GridSummaryColumn() + { + MappingName = "EmployeeID", + Name = "EmployeeID", + SummaryType = SummaryType.CountAggregate, + Format = "Total: {Count}" + }); + SummaryColumns.Add(new GridSummaryColumn() + { + MappingName = "EmployeeSalary", + Name = "EmployeeSalary", + SummaryType = SummaryType.DoubleAggregate, + Format = "Total: {Sum}" + }); + } +} +``` + +Refer to the following code example to bind the attached property in DataGrid. + +#### XAML + +``` xml + + +``` \ No newline at end of file