Skip to main content
Tag

PivotGridField.PrintHeaderTemplateSelector Property

Gets or sets a template selector that chooses a print template for field headers based on custom logic. This is a dependency property.

Namespace: DevExpress.Xpf.PivotGrid

Assembly: DevExpress.Xpf.PivotGrid.v24.2.dll

NuGet Package: DevExpress.Wpf.PivotGrid

Declaration

public DataTemplateSelector PrintHeaderTemplateSelector { get; set; }

Property Value

Type Description
DataTemplateSelector

A DataTemplateSelector descendant that chooses a template based on custom logic.

Remarks

A template that defines the presentation of the field header when the pivot grid is printed is specified by the PivotGridField.PrintHeaderTemplate property. If you have more than one template that can be used to render the field header, you can implement custom logic to choose the required template. To do this, derive from the DataTemplateSelector class, implement the SelectTemplate method that returns a template which meets the required condition, and assign an instance of this class to the PrintHeaderTemplateSelector property.

The PrintHeaderTemplateSelector is in effect only if the PivotGridField.PrintHeaderTemplate property is set to null (Nothing in Visual Basic). Otherwise, the PivotGridField.PrintHeaderTemplate template is used.

To learn more, see Printing and Exporting.

Example

This example demonstrates how to select print templates for the DXPivotGrid elements based on a custom logic.

The logic for selecting the data cell print template is based on the ratio of the data cell value to the grand total value. If the ratio is between 0.2 and 0.8, the template selector applies a template that highlights the cell text and adds the warning sign to the cell.

using System;
using System.Windows;
using System.Windows.Controls;
using DevExpress.Xpf.PivotGrid;
using DevExpress.Xpf.Printing;

namespace DXPivotGrid_SelectingPrintTemplate {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
            picotGridControl1.DataSource =
                new nwindDataSetTableAdapters.SalesPersonTableAdapter().GetData();
        }
        private void btnPrint_Click(object sender, RoutedEventArgs e) {
            PrintHelper.ShowPrintPreview(this, picotGridControl1);
        }
    }
    public class CellTemplateSelector : DataTemplateSelector {
        public override DataTemplate SelectTemplate(object item, DependencyObject container) {
            Window mainWindow = Application.Current.MainWindow;
            CellElementData cell = (CellElementData)item;
            // Calculate the ratio of the cell value to the grand total.
            double share = Convert.ToDouble(cell.Value) / Convert.ToDouble(cell.ColumnTotalValue);

            // Apply the Normal template to the Column Grand Total cells.
            if (cell.ColumnValue == null)
                return mainWindow.FindResource("NormalCellTemplate") as DataTemplate;

            // If the ratio is far from 0.5, use the Highlighted template.
            // Otherwise, use the Normal template.
            if (share > 0.8 || share < 0.2)
                return mainWindow.FindResource("HighlightedCellTemplate") as DataTemplate;
            else
                return mainWindow.FindResource("NormalCellTemplate") as DataTemplate;
        }
    }
}
See Also