[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Collapse]WPF Controls
  Prerequisites
 [Expand]What's Installed
 [Expand]Common Concepts
 [Expand]MVVM Framework
 [Collapse]Controls and Libraries
   Reporting
  [Expand]Data Grid
  [Expand]Ribbon, Bars and Menu
  [Expand]Charts Suite
  [Collapse]Pivot Grid
   [Expand]Getting Started
   [Expand]Fundamentals
   [Expand]Binding to Data
   [Expand]Data Shaping
   [Expand]Data Analysis
   [Expand]Layout
   [Expand]Printing and Exporting
   [Expand]End-User Interaction
   [Expand]Appearance
   [Collapse]MVVM Enhancements
     Binding to a Collection of Fields
     Binding to a Collection of Groups
   [Expand]UI Elements
   [Expand]End-User Capabilities
   [Expand]Examples
  [Expand]Scheduler
  [Expand]Spreadsheet
  [Expand]Rich Text Editor
  [Expand]Tree List
  [Expand]Gauge Controls
  [Expand]Map Control
  [Expand]Layout Management
  [Expand]Windows Modern UI
  [Expand]Printing-Exporting
  [Expand]Data Editors
  [Expand]Navigation Controls
  [Expand]Spell Checker
  [Expand]Property Grid
  [Expand]PDF Viewer
  [Expand]TreeMap Control
  [Expand]Gantt Control
  [Expand]Diagram Control
  [Expand]Windows and Utility Controls
   Dialogs, Notifications and Panels
  [Expand]Scheduler (legacy)
 [Expand]Scaffolding Wizard
 [Expand]Localization
  Redistribution and Deployment
  Get More Help
 [Expand]API Reference
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Binding to a Collection of Groups

When engineering a WPF application using the Model View ViewModel (MVVM) architectural pattern, you may be required to describe field groups in a Model or ViewModel. The Pivot Grid can be bound to a collection of objects containing group settings, described in a Model or ViewModel, thus minimizing the need for 'code-behind'.

Expanded View Model Implementation

Note

In this tutorial PivotGrid is bound to the Sales Person view of the Northwind database. You can find it at C:\Users\Public\Documents\DevExpress Demos 18.2\Components\Data\nwind.mdb.

Create a view model. In this tutorial, the view model includes the following classes:

  • ViewModel - the Sales Person view model.
  • Field - describes the Pivot Grid fields. To get more information about field templates, see Binding to a Collection of Fields.
  • FieldTemplateSelector - describes the Pivot Grid template selector. This class allows you to choose the required template based on the specified condition.
  • Group - describes the Pivot Grid groups. This class provides properties that correspond to settings common to all Pivot Grid field groups.
Note

If the Groups collection might be changed after it has been assigned to the Pivot Grid control, it should implement the INotifyCollectionChanged interface, so that changes made within a View Model are automatically reflected by the Pivot Grid.

Expanded Group Templates and Selector

The Pivot Grid Control generates groups based on group templates. Using a template, you can create an unlimited number of field groups in an unlimited number of Pivot Grid controls. In this example, there is one group template: DefaultGroupTemplate.

To avoid performance issues when binding to field properties, use the dxci:DependencyObjectExtensions.DataContext attached property.

If all Pivot Grid groups can be described using a single template, you have no need to create a field template selector:

To create more then one template for field groups to allow choosing the required template based on a specified condition, create the Template Selector. After that, assign this class containing the specified condition to the Pivot Grid's PivotGridControl.GroupGeneratorTemplateSelector property.

You can create a style to specify settings common to all field groups generated using different templates. You can specify bindings to ViewModel properties within a style. This style should be assigned to the PivotGridControl.GroupGeneratorStyle property.

Expanded Customizing the WPF DXPivotGrid

Finally, specify the Pivot Grid's PivotGridControl.DataSource, PivotGridControl.GroupsSource and PivotGridControl.GroupGeneratorTemplate.

Member Description
PivotGridControl.DataSource Specifies the Pivot Grid's data source.
PivotGridControl.GroupsSource Specifies the source from which the Pivot Grid generates groups.
PivotGridControl.GroupGeneratorTemplate Specifies the group template.

The following code shows how to configure the Pivot Grid control using the ViewModel.

The image below illustrates the result.

Expanded Example

Is this topic helpful?​​​​​​​