This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
/
MainWindow.xaml.cs
37 lines (34 loc) · 1.6 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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;
}
}
}