Skip to content

Commit dabe38f

Browse files
Committed the changes
1 parent 1e76777 commit dabe38f

File tree

1 file changed

+76
-33
lines changed

1 file changed

+76
-33
lines changed

winui/DataGrid/Printing.md

Lines changed: 76 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ To display the print preview window, you need to pass the `Window` instance as a
1414

1515
{% tabs %}
1616
{% highlight c# %}
17+
1718
public sealed partial class MainWindow : Window
1819
{
1920
public MainWindow()
@@ -26,6 +27,7 @@ public sealed partial class MainWindow : Window
2627
sfDataGrid.Print(this);
2728
}
2829
}
30+
2931
{% endhighlight %}
3032
{% endtabs %}
3133

@@ -35,8 +37,10 @@ SfDataGrid provides various options to customize print preview settings using [S
3537

3638
{% tabs %}
3739
{% highlight c# %}
40+
3841
sfDataGrid.PrintSettings.CanRepeatHeaders = true;
3942
sfDataGrid.Print(window);
43+
4044
{% endhighlight %}
4145
{% endtabs %}
4246

@@ -52,8 +56,10 @@ SfDataGrid provides support to scale rows or columns or both while printing to f
5256

5357
{% tabs %}
5458
{% highlight c# %}
59+
5560
sfDataGrid.PrintSettings.ScalingOption = PrintScalingOptions.FitAllColumnsOnOnePage;
5661
sfDataGrid.Print(window);
62+
5763
{% endhighlight %}
5864
{% endtabs %}
5965

@@ -63,8 +69,10 @@ Column headers can be printed on each page by enabling [PrintSettings.CanRepeatH
6369

6470
{% tabs %}
6571
{% highlight c# %}
72+
6673
sfDataGrid.PrintSettings.CanRepeatHeaders = true;
6774
sfDataGrid.Print(window);
75+
6876
{% endhighlight %}
6977
{% endtabs %}
7078

@@ -74,18 +82,23 @@ You can change the text direction in print page by using [PrintSettings.FlowDire
7482

7583
{% tabs %}
7684
{% highlight c# %}
85+
7786
sfDataGrid.PrintSettings.FlowDirection = FlowDirection.RightToLeft;
7887
sfDataGrid.Print(window);
88+
7989
{% endhighlight %}
8090
{% endtabs %}
8191

8292
### Print with StackedHeaders
8393

8494
SfDataGrid provides support to print the StackedHeaders by setting the [PrintSettings.CanPrintStackedHeaders](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.Print.DataGridPrintSettings.html#Syncfusion_UI_Xaml_DataGrid_Print_DataGridPrintSettings_CanPrintStackedHeaders) as ‘true’.
95+
8596
{% tabs %}
8697
{% highlight c# %}
98+
8799
sfDataGrid.PrintSettings.CanPrintStackedHeaders = true;
88100
sfDataGrid.Print(window);
101+
89102
{% endhighlight %}
90103
{% endtabs %}
91104

@@ -103,8 +116,10 @@ Orientation can also be changed in print dialog at runtime by selecting a option
103116

104117
{% tabs %}
105118
{% highlight c# %}
119+
106120
sfDataGrid.PrintSettings.Orientation = PrintOrientation.Landscape;
107121
sfDataGrid.Print(window);
122+
108123
{% endhighlight %}
109124
{% endtabs %}
110125

@@ -114,8 +129,10 @@ SfDataGrid provides support to change the page size. Page size can be changed by
114129

115130
{% tabs %}
116131
{% highlight c# %}
132+
117133
sfDataGrid.PrintSettings.PageSize = new Size(800, 800);
118134
sfDataGrid.Print(window);
135+
119136
{% endhighlight %}
120137
{% endtabs %}
121138

@@ -125,8 +142,10 @@ SfDataGrid provides support to change the page padding to adjust content in prin
125142

126143
{% tabs %}
127144
{% highlight c# %}
145+
128146
sfDataGrid.PrintSettings.PagePadding = new Thickness(10, 20, 10, 20);
129147
sfDataGrid.Print(window);
148+
130149
{% endhighlight %}
131150
{% endtabs %}
132151

@@ -140,14 +159,16 @@ Steps to add page header while printing,
140159

141160
{% tabs %}
142161
{% highlight xaml %}
143-
<Application.Resources>
144-
<DataTemplate x:Key="PageHeaderTemplate">
145-
<Grid Background="Gray">
146-
<TextBlock Text="Syncfusion" FontSize="18" FontWeight="Bold"
147-
Foreground="White" HorizontalAlignment="Center"/>
148-
</Grid>
149-
</DataTemplate>
150-
</Application.Resources>
162+
163+
&lt;Application.Resources&gt;
164+
&lt;DataTemplate x:Key="PageHeaderTemplate"&gt;
165+
&lt;Grid Background="Gray"&gt;
166+
&lt;TextBlock Text="Syncfusion" FontSize="18" FontWeight="Bold"
167+
Foreground="White" HorizontalAlignment="Center"/&gt;
168+
&lt;/Grid&gt;
169+
&lt;/DataTemplate&gt;
170+
&lt;/Application.Resources&gt;
171+
151172
{% endhighlight %}
152173
{% endtabs %}
153174

@@ -156,9 +177,11 @@ Steps to add page header while printing,
156177

157178
{% tabs %}
158179
{% highlight c# %}
180+
159181
sfDataGrid.PrintSettings.PageHeaderHeight = 30;
160182
sfDataGrid.PrintSettings.HeaderTemplate = Application.Current.Resources["PageHeaderTemplate"] as DataTemplate;
161183
sfDataGrid.Print(window);
184+
162185
{% endhighlight %}
163186
{% endtabs %}
164187

@@ -170,31 +193,30 @@ N> [DataGridPrintManager](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xam
170193

171194
### Printing Current Date time
172195

173-
You can print current Date and Time at each page by setting the [FooterHeight](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.Print.DataGridPrintSettings.html#Syncfusion_UI_Xaml_DataGrid_Print_DataGridPrintSettings_FooterHeight), [FooterTemplate](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.Print.DataGridPrintSettings.html#Syncfusion_UI_Xaml_DataGrid_Print_DataGridPrintSettings_FooterTemplate) properties in [PrintSettings](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.SfDataGrid.html#Syncfusion_UI_Xaml_DataGrid_SfDataGrid_PrintSettings).
196+
You can print current Date and Time at each page by setting the [FooterHeight](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.Print.DataGridPrintSettings.html#Syncfusion_UI_Xaml_DataGrid_Print_DataGridPrintSettings_FooterHeight), [FooterTemplate](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.Print.DataGridPrintSettings.html#Syncfusion_UI_Xaml_DataGrid_Print_DataGridPrintSettings_FooterTemplate) properties in [PrintSettings](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.SfDataGrid.html#Syncfusion_UI_Xaml_DataGrid_SfDataGrid_PrintSettings).
197+
174198

175199
{% tabs %}
176200
{% highlight xaml %}
177-
178-
<Grid.Resources>
179-
<local:OrderInfoViewModel x:Key="viewModel"/>
180-
<DataTemplate x:Key="PageFooterTemplate">
181-
<Grid>
182-
<TextBlock HorizontalAlignment="Center" FontSize="20" VerticalAlignment="Center"
183-
Text="{Binding Path=Date, Source={StaticResource viewModel}}"/>
184-
</Grid>
185-
</DataTemplate>
186-
</Grid.Resources>
187-
201+
&lt;Grid.Resources&gt;
202+
&lt;local:OrderInfoViewModel x:Key="viewModel"/&gt;
203+
&lt;DataTemplate x:Key="PageFooterTemplate"&gt;
204+
&lt;Grid&gt;
205+
&lt;TextBlock HorizontalAlignment="Center" FontSize="20" VerticalAlignment="Center"
206+
Text="{Binding Path=Date, Source={StaticResource viewModel}}"/&gt;
207+
&lt;/Grid&gt;
208+
&lt;/DataTemplate&gt;
209+
&lt;/Grid.Resources&gt;
188210
{% endhighlight %}
189-
{% highlight c# %}
190211

212+
{% highlight c# %}
191213
sfDataGrid.PrintSettings.FooterHeight = 30;
192214
sfDataGrid.PrintSettings.FooterTemplate = grid.Resources["PageFooterTemplate"] as DataTemplate;
193215
sfDataGrid.Print(window);
194-
195216
{% endhighlight %}
196217
{% endtabs %}
197218

219+
198220
![WinUI DataGrid displays Current DateTime in Printing](Printing-images/winui-datagrid-printing-with-current-date-time.png)
199221

200222
## Printing with styles
@@ -204,20 +226,22 @@ You can print SfDataGrid as it displayed in View by setting [PrintSettings.CanPr
204226

205227
{% tabs %}
206228
{% highlight c# %}
229+
207230
sfDataGrid.PrintSettings.CanPrintStyles = true;
208231
sfDataGrid.Print(window);
232+
209233
{% endhighlight %}
210234
{% endtabs %}
211235

212236
[GridHeaderCellControl](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.GridHeaderCellControl.html) style customized and the same style will be exported while printing by setting [PrintSettings.CanPrintStyles](https://help.syncfusion.com/cr/winui/Syncfusion.UI.Xaml.DataGrid.Print.DataGridPrintSettings.html#Syncfusion_UI_Xaml_DataGrid_Print_DataGridPrintSettings_CanPrintStyles) to true.
213237

214238
{% tabs %}
215239
{% highlight xaml %}
216-
<Grid.Resources>
217-
<Style TargetType="dataGrid:GridHeaderCellControl">
218-
<Setter Property="Background" Value="LightPink"/>
219-
</Style>
220-
</Grid.Resources>
240+
&lt;Grid.Resources&gt;
241+
&lt;Style TargetType="dataGrid:GridHeaderCellControl"&gt;
242+
&lt;Setter Property="Background" Value="LightPink"/&gt;
243+
&lt;/Style&gt;
244+
&lt;/Grid.Resources&gt;
221245
{% endhighlight %}
222246
{% endtabs %}
223247

@@ -233,6 +257,7 @@ SfDataGrid allows you to set different row height for specific rows while printi
233257

234258
{% tabs %}
235259
{% highlight c# %}
260+
236261
public class CustomPrintManager : DataGridPrintManager
237262
{
238263
public CustomPrintManager(SfDataGrid grid , Window window)
@@ -253,8 +278,10 @@ public class CustomPrintManager : DataGridPrintManager
253278

254279
{% tabs %}
255280
{% highlight c# %}
281+
256282
sfDataGrid.PrintSettings.PrintManager = new CustomPrintManager(this.sfDataGrid , this);
257283
sfDataGrid.PrintSettings.PrintManager.Print();
284+
258285
{% endhighlight %}
259286
{% endtabs %}
260287

@@ -267,6 +294,7 @@ Here, unbound row is excluded while printing. Likewise, you can hide any row bas
267294

268295
{% tabs %}
269296
{% highlight c# %}
297+
270298
public class CustomPrintManager : DataGridPrintManager
271299
{
272300
public CustomPrintManager(SfDataGrid grid , Window window)
@@ -284,11 +312,12 @@ public class CustomPrintManager : DataGridPrintManager
284312
{% endhighlight %}
285313
{% endtabs %}
286314

287-
288315
{% tabs %}
289316
{% highlight c# %}
317+
290318
sfDataGrid.PrintSettings.PrintManager = new CustomPrintManager(this.sfDataGrid , this);
291319
sfDataGrid.PrintSettings.PrintManager.Print();
320+
292321
{% endhighlight %}
293322
{% endtabs %}
294323

@@ -298,6 +327,7 @@ SfDataGrid allows you to the exclude the columns while printing the grid. You ca
298327

299328
{% tabs %}
300329
{% highlight c# %}
330+
301331
public class CustomPrintManager : DataGridPrintManager
302332
{
303333
public CustomPrintManager(SfDataGrid grid , Window window)
@@ -316,11 +346,12 @@ public class CustomPrintManager : DataGridPrintManager
316346
{% endhighlight %}
317347
{% endtabs %}
318348

319-
320349
{% tabs %}
321350
{% highlight c# %}
351+
322352
sfDataGrid.PrintSettings.PrintManager = new CustomPrintManager(this.sfDataGrid , this);
323353
sfDataGrid.PrintSettings.PrintManager.Print();
354+
324355
{% endhighlight %}
325356
{% endtabs %}
326357

@@ -332,6 +363,7 @@ SfDataGrid allows you to change column header text while printing the grid. You
332363

333364
{% tabs %}
334365
{% highlight c# %}
366+
335367
public class CustomPrintManager : DataGridPrintManager
336368
{
337369
public CustomPrintManager(SfDataGrid grid , Window window)
@@ -350,11 +382,12 @@ public class CustomPrintManager : DataGridPrintManager
350382
{% endhighlight %}
351383
{% endtabs %}
352384

353-
354385
{% tabs %}
355386
{% highlight c# %}
387+
356388
sfDataGrid.PrintSettings.PrintManager = new CustomPrintManager(this.sfDataGrid , this);
357389
sfDataGrid.PrintSettings.PrintManager.Print();
390+
358391
{% endhighlight %}
359392
{% endtabs %}
360393

@@ -366,6 +399,7 @@ You can apply row styles based on custom logic by overriding [GetPrintGridCell](
366399

367400
{% tabs %}
368401
{% highlight c# %}
402+
369403
public class CustomPrintManager : DataGridPrintManager
370404
{
371405
public CustomPrintManager(SfDataGrid grid , Window window)
@@ -389,11 +423,12 @@ public class CustomPrintManager : DataGridPrintManager
389423
{% endhighlight %}
390424
{% endtabs %}
391425

392-
393426
{% tabs %}
394427
{% highlight c# %}
428+
395429
sfDataGrid.PrintSettings.PrintManager = new CustomPrintManager(this.sfDataGrid , this);
396430
sfDataGrid.PrintSettings.PrintManager.Print();
431+
397432
{% endhighlight %}
398433
{% endtabs %}
399434

@@ -464,6 +499,7 @@ SfDataGrid allows you to apply alternative row style by overriding [GetPrintGrid
464499

465500
{% tabs %}
466501
{% highlight c# %}
502+
467503
public class CustomPrintManager : DataGridPrintManager
468504
{
469505
public CustomPrintManager(SfDataGrid grid , Window window)
@@ -483,11 +519,12 @@ public class CustomPrintManager : DataGridPrintManager
483519
{% endhighlight %}
484520
{% endtabs %}
485521

486-
487522
{% tabs %}
488523
{% highlight c# %}
524+
489525
sfDataGrid.PrintSettings.PrintManager = new CustomPrintManager(this.sfDataGrid , this);
490526
sfDataGrid.PrintSettings.PrintManager.Print();
527+
491528
{% endhighlight %}
492529
{% endtabs %}
493530

@@ -499,6 +536,7 @@ You can apply column styles based on custom logic by overriding [GetPrintGridCel
499536

500537
{% tabs %}
501538
{% highlight c# %}
539+
502540
public class CustomPrintManager : DataGridPrintManager
503541
{
504542
public CustomPrintManager(SfDataGrid grid , Window window)
@@ -516,11 +554,12 @@ public class CustomPrintManager : DataGridPrintManager
516554
{% endhighlight %}
517555
{% endtabs %}
518556

519-
520557
{% tabs %}
521558
{% highlight c# %}
559+
522560
sfDataGrid.PrintSettings.PrintManager = new CustomPrintManager(this.sfDataGrid , this);
523561
sfDataGrid.PrintSettings.PrintManager.Print();
562+
524563
{% endhighlight %}
525564
{% endtabs %}
526565

@@ -534,6 +573,7 @@ Selected rows can be printed by overriding [GetSourceListForPrinting](https://he
534573

535574
{% tabs %}
536575
{% highlight c# %}
576+
537577
public class CustomPrintManager : DataGridPrintManager
538578
{
539579
public CustomPrintManager(SfDataGrid grid , Window window)
@@ -566,10 +606,13 @@ public class CustomPrintManager : DataGridPrintManager
566606
}
567607
{% endhighlight %}
568608
{% endtabs %}
609+
569610
{% tabs %}
570611
{% highlight c# %}
612+
571613
sfDataGrid.PrintSettings.PrintManager = new CustomPrintManager(this.sfDataGrid , this);
572614
sfDataGrid.PrintSettings.PrintManager.Print();
615+
573616
{% endhighlight %}
574617
{% endtabs %}
575618

0 commit comments

Comments
 (0)