[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]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]CodeRush
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Binding to a Collection of Fields

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

Expanded View Model Implementation

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.1\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. This class provides properties that correspond to settings common to all Pivot Grid fields.
  • FieldTemplateSelector - describes the Pivot Grid template selector. This class allows you to choose the required template based on the specified condition.
Note

If the Fields 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 Field Templates and Selector

The Pivot Grid Control generates fields based on field templates. Using a template, you can create an unlimited number of fields in an unlimited number of Pivot Grid controls. In this example, there are two field templates: DefaultFieldTemplate and ComboColumnTemplate.

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

To choose the required template based on the specified condition, use the Template Selector. In this example, the template selector is represented by the FieldTemplateSelector class:

If all Pivot Grid fields can be described using a single template, you have no need to create a field template selector. Instead, assign this template to the Pivot Grid's PivotGridControl.FieldGeneratorTemplate property.

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

Expanded Customizing the WPF DXPivotGrid

Finally, specify the Pivot Grid's PivotGridControl.DataSource, PivotGridControl.FieldsSource and PivotGridControl.FieldGeneratorTemplateSelector.

Member

Description

PivotGridControl.DataSource Specifies the Pivot Grid's data source.
PivotGridControl.FieldsSource Specifies the source from which the Pivot Grid generates fields.
PivotGridControl.FieldGeneratorTemplateSelector Specifies the field template selector, which returns a template for each field based on the specified condition.

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

The image below shows the result. As you can see, the OrderDate field has a Calendar icon in its field header.

Expanded Example

Expanded See Also

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