GridViewBase.PrintGroupRowTemplate Property
Gets or sets the template that defines the presentation of group rows when the grid is printed. This is a dependency property.
Namespace: DevExpress.Xpf.Grid
Assembly: DevExpress.Xpf.Grid.v19.1.dll
Declaration
public DataTemplate PrintGroupRowTemplate { get; set; }
Public Property PrintGroupRowTemplate As DataTemplate
Property Value
Type |
Description |
DataTemplate |
A DataTemplate object that defines the presentation of group rows when the grid is printed.
|
The templates supplied by the DXGrid, allow you to completely replace the look and feel of visual elements while maintaining their existing behavior.
<DataTemplate x:Key="CustomPrintGroupRowTemplate">
<ContentControl Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource TemplatedParent}}">
<Grid DataContext="{Binding Path=DataContext.Content, RelativeSource={RelativeSource TemplatedParent}}">
...
</Grid>
</ContentControl>
</DataTemplate>
To learn more, see Appearance Customization.
Example
The following example demonstrates how to align group summaries to the right edge of paper when printing a DXGrid control with groups.
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using DevExpress.Xpf.Editors;
using DevExpress.Xpf.Grid;
using System.Collections;
using DevExpress.Xpf.Core.Native;
using System.ComponentModel;
namespace Printing_GroupSummaryAlignment {
public partial class Window1 : Window {
public Window1() {
InitializeComponent();
List<TestData> list = new List<TestData>();
for (int i = 0; i < 100; i++) {
list.Add(new TestData() {
Number1 = i,
Number2 = (i + 10) / 10,
Text1 = "row " + i,
Text2 = "ROW " + i
});
}
DataContext = list;
}
private void showPreviewButton_Click(object sender, RoutedEventArgs e) {
view.ShowPrintPreviewDialog(this);
}
}
public class TestData {
public int Number1 { get; set; }
public int Number2 { get; set; }
public string Text1 { get; set; }
public string Text2 { get; set; }
}
public class CollectionConverterDecorator : Border, IWeakEventListener {
public string SummaryText {
get { return (string)GetValue(SummaryTextProperty); }
set { SetValue(SummaryTextProperty, value); }
}
public static readonly DependencyProperty SummaryTextProperty =
DependencyProperty.Register("SummaryText", typeof(string), typeof(CollectionConverterDecorator), new PropertyMetadata(null));
public IList Collection {
get { return (IList)GetValue(CollectionProperty); }
set { SetValue(CollectionProperty, value); }
}
public static readonly DependencyProperty CollectionProperty =
DependencyProperty.Register("Collection", typeof(IList), typeof(CollectionConverterDecorator), new PropertyMetadata(null, OnCollectionChanged));
static void OnCollectionChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) {
((CollectionConverterDecorator)d).OnCollectionChanged();
}
IBindingList bindingList;
void OnCollectionChanged() {
if(bindingList != null)
ListChangedEventManager.RemoveListener(bindingList, this);
bindingList = BindingListAdapter.CreateFromList(Collection, ItemPropertyNotificationMode.All);
if(bindingList != null)
ListChangedEventManager.AddListener(bindingList, this);
}
#region IWeakEventListener Members
bool IWeakEventListener.ReceiveWeakEvent(System.Type managerType, object sender, System.EventArgs e) {
if(managerType == typeof(ListChangedEventManager)) {
InvalidateMeasure();
return true;
}
return false;
}
#endregion
protected override Size MeasureOverride(Size constraint) {
if(bindingList != null) {
SummaryText = GetSummaryText();
}
return base.MeasureOverride(constraint);
}
string GetSummaryText() {
string res = string.Empty;
foreach(GridGroupSummaryData item in bindingList) {
res += item.Text;
if(!item.IsLast)
res += ", ";
}
return res;
}
}
}
<Window x:Class="Printing_GroupSummaryAlignment.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:dxp="http://schemas.devexpress.com/winfx/2008/xaml/printing" xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors" xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid" xmlns:local="clr-namespace:Printing_GroupSummaryAlignment" Title="Window1" Height="350" Width="450">
<DockPanel>
<Button Name="showPreviewButton" DockPanel.Dock="Top" Click="showPreviewButton_Click">
Show Print Preview
</Button>
<dxg:GridControl x:Name="grid" ItemsSource="{Binding}">
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="Number1" />
<dxg:GridColumn FieldName="Number2" GroupIndex="0" />
<dxg:GridColumn FieldName="Text1" />
<dxg:GridColumn FieldName="Text2" />
</dxg:GridControl.Columns>
<dxg:GridControl.GroupSummary>
<dxg:GridSummaryItem SummaryType="Count" />
<dxg:GridSummaryItem FieldName="Number2" SummaryType="Sum" />
</dxg:GridControl.GroupSummary>
<dxg:GridControl.View>
<dxg:TableView x:Name="view" AutoWidth="True" NavigationStyle="Row">
<dxg:TableView.PrintGroupRowTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<dxg:CellFillControl>
<dxg:CellFillControl.Template>
<ControlTemplate>
<dxe:TextEdit Name="PART_Edit" Style="{Binding Path=Content.(dxg:GridPrintingHelper.PrintRowInfo).PrintGroupRowStyle}" Background="Transparent" BorderThickness="{Binding Path=Content.(dxg:GridPrintingHelper.PrintRowInfo).PrintDataIndentBorderThickness}" Margin="{Binding Path=Content.(dxg:GridPrintingHelper.PrintRowInfo).PrintDataIndentMargin}" Width="{Binding Path=Content.(dxg:GridPrintingHelper.PrintRowInfo).PrintDataIndent}">
<dxp:ExportSettings.OnPageUpdater>
<dxg:LastOnPageUpdater />
</dxp:ExportSettings.OnPageUpdater>
</dxe:TextEdit>
</ControlTemplate>
</dxg:CellFillControl.Template>
</dxg:CellFillControl>
<dxg:GroupRowContentControl>
<dxg:GroupRowContentControl.Template>
<ControlTemplate>
<DockPanel Width="{Binding Path=Content.(dxg:GridPrintingHelper.PrintRowInfo).TotalHeaderWidth}">
<dxe:TextEdit Name="PART_Edit" BorderThickness="1,0,0,1" Style="{Binding Path=Content.(dxg:GridPrintingHelper.PrintRowInfo).PrintGroupRowStyle}" EditValue="{Binding Path=Content.GroupValue.DisplayText, Mode=OneWay}" DockPanel.Dock="Left" />
<local:CollectionConverterDecorator Collection="{Binding Path=Content.GroupSummaryData, Mode=OneWay}" x:Name="collectionConverterDecorator">
<dxe:TextEdit BorderThickness="0,0,1,1" Style="{Binding Path=Content.(dxg:GridPrintingHelper.PrintRowInfo).PrintGroupRowStyle}" EditValue="{Binding Path=SummaryText, Mode=OneWay, ElementName=collectionConverterDecorator}" HorizontalContentAlignment="Right" />
</local:CollectionConverterDecorator>
</DockPanel>
</ControlTemplate>
</dxg:GroupRowContentControl.Template>
</dxg:GroupRowContentControl>
</StackPanel>
</DataTemplate>
</dxg:TableView.PrintGroupRowTemplate>
</dxg:TableView>
</dxg:GridControl.View>
</dxg:GridControl>
</DockPanel>
</Window>
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Documents
Imports DevExpress.Xpf.Editors
Imports DevExpress.Xpf.Grid
Imports System.Collections
Imports DevExpress.Xpf.Core.Native
Imports System.ComponentModel
Imports System
Namespace Printing_GroupSummaryAlignment
Partial Public Class Window1
Inherits Window
Public Sub New()
InitializeComponent()
Dim list As New List(Of TestData)()
For i As Integer = 0 To 99
list.Add(New TestData() With {.Number1 = i, .Number2 = Convert.ToInt32((i + 10) / 10), .Text1 = "row " & i, .Text2 = "ROW " & i})
Next i
DataContext = list
End Sub
Private Sub showPreviewButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
view.ShowPrintPreviewDialog(Me)
End Sub
End Class
Public Class TestData
Private privateNumber1 As Integer
Public Property Number1() As Integer
Get
Return privateNumber1
End Get
Set(ByVal value As Integer)
privateNumber1 = value
End Set
End Property
Private privateNumber2 As Integer
Public Property Number2() As Integer
Get
Return privateNumber2
End Get
Set(ByVal value As Integer)
privateNumber2 = value
End Set
End Property
Private privateText1 As String
Public Property Text1() As String
Get
Return privateText1
End Get
Set(ByVal value As String)
privateText1 = value
End Set
End Property
Private privateText2 As String
Public Property Text2() As String
Get
Return privateText2
End Get
Set(ByVal value As String)
privateText2 = value
End Set
End Property
End Class
Public Class CollectionConverterDecorator
Inherits Border
Implements IWeakEventListener
Public Property SummaryText() As String
Get
Return CStr(GetValue(SummaryTextProperty))
End Get
Set(ByVal value As String)
SetValue(SummaryTextProperty, value)
End Set
End Property
Public Shared ReadOnly SummaryTextProperty As DependencyProperty = DependencyProperty.Register("SummaryText", GetType(String), GetType(CollectionConverterDecorator), New PropertyMetadata(Nothing))
Public Property Collection() As IList
Get
Return CType(GetValue(CollectionProperty), IList)
End Get
Set(ByVal value As IList)
SetValue(CollectionProperty, value)
End Set
End Property
Public Shared ReadOnly CollectionProperty As DependencyProperty = DependencyProperty.Register("Collection",
GetType(IList),
GetType(CollectionConverterDecorator),
New PropertyMetadata(Nothing, AddressOf OnCollectionChanged))
Private Shared Sub OnCollectionChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
CType(d, CollectionConverterDecorator).OnCollectionChanged()
End Sub
Private bindingList As IBindingList
Private Sub OnCollectionChanged()
If bindingList IsNot Nothing Then
ListChangedEventManager.RemoveListener(bindingList, Me)
End If
bindingList = BindingListAdapter.CreateFromList(Collection, ItemPropertyNotificationMode.All)
If bindingList IsNot Nothing Then
ListChangedEventManager.AddListener(bindingList, Me)
End If
End Sub
#Region "IWeakEventListener Members"
Private Function ReceiveWeakEvent(ByVal managerType As System.Type, ByVal sender As Object, ByVal e As System.EventArgs) As Boolean Implements IWeakEventListener.ReceiveWeakEvent
If managerType Is GetType(ListChangedEventManager) Then
InvalidateMeasure()
Return True
End If
Return False
End Function
#End Region
Protected Overrides Function MeasureOverride(ByVal constraint As Size) As Size
If bindingList IsNot Nothing Then
SummaryText = GetSummaryText()
End If
Return MyBase.MeasureOverride(constraint)
End Function
Private Function GetSummaryText() As String
Dim res As String = String.Empty
For Each item As GridGroupSummaryData In bindingList
res &= item.Text
If (Not item.IsLast) Then
res &= ", "
End If
Next item
Return res
End Function
End Class
End Namespace
<Application x:Class="Printing_GroupSummaryAlignment.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" StartupUri="Window1.xaml">
<Application.Resources>
</Application.Resources>
</Application>
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Configuration
Imports System.Data
Imports System.Linq
Imports System.Windows
Namespace Printing_GroupSummaryAlignment
''' <summary>
''' Interaction logic for App.xaml
''' </summary>
Partial Public Class App
Inherits Application
End Class
End Namespace
See Also