wpf-119773-controls-and-libraries-scheduler-printing.md
The WPF Scheduler Suite uses DevExpress Reporting to create a printable scheduler report with the SchedulerControl’s data, preview it and print or export it to PDF.
To print the SchedulerControl, create a scheduler report template, bind it to the scheduler print adapter, and show the resulting document in a Document Preview window. The Document Preview window UI commands enable users to print the document and save it as a PDF or image file.
Add the following NuGet package to the project to be able to print the Scheduler:
A scheduler report template is an XtraSchedulerReport class object, which is a XtraReport class descendant, offering many useful features available in XtraReports.
XtraScheduler Reports are created similarly to XtraReports. See the Getting Started with DevExpress Reporting document for more information on reports.
Refer to the How to: Print a Scheduler Using Reports from a Document Preview Window document for instructions on how to create a scheduler report.
The report retrieves scheduler data from the print adapter (SchedulerPrintAdapter object) the SchedulerPrintAdapter.AssignToReport method assigns to it.
The scheduler report requires a print adapter to interact with a scheduler control. A print adapter is the SchedulerPrintAdapter object instance accessible using the SchedulerControl.SchedulerPrintAdapter property. To bind a report to a print adapter, call the SchedulerPrintAdapter.AssignToReport method.
The print adapter composes a data set used in the report and allows you to filter the Scheduler data by providing a set of validation events which can change appointment and resource collections before they are passed to a report, or adjust a report’s time interval and work time. For example, you can handle the SchedulerPrintAdapter.ValidateAppointments event to print appointments which meet specific criteria.
The base XtraReport class is a report bands container with report controls placed inside them. Scheduler Reporting adds a set of special controls described in the Scheduler Report Controls and Components document.
To preview a report, open it in the Document Preview window. The DocumentPreviewControl enables the end-user to print a report or export it to PDF.
This code snippet contains the PrintScheduler method which performs the following tasks:
using DevExpress.Mvvm;
using DevExpress.Xpf.Printing;
using DevExpress.Xpf.Printing.Native;
using DevExpress.Xpf.Scheduling;
using DevExpress.XtraPrinting.Native;
using System.Windows;
namespace PrintingExample {
public static class MyPrintHelper {
public static Window mainWindow { get; set; }
public static void PrintScheduler(SchedulerControl scheduler) {
XtraSchedulerReport1 report = new XtraSchedulerReport1();
DateTimeRange dateTimeRange = scheduler.VisibleIntervals[0];
scheduler.SchedulerPrintAdapter.DateTimeRange = dateTimeRange;
scheduler.SchedulerPrintAdapter.AssignToReport(report);
PrintHelper.ShowPrintPreview(mainWindow, report);
}
}
}
Imports DevExpress.Mvvm
Imports DevExpress.Xpf.Printing
Imports DevExpress.Xpf.Printing.Native
Imports DevExpress.Xpf.Scheduling
Imports DevExpress.XtraPrinting.Native
Imports System.Windows
Namespace PrintingExample
Public NotInheritable Class MyPrintHelper
Private Sub New()
End Sub
Public Shared Property mainWindow() As Window
Public Shared Sub PrintScheduler(ByVal scheduler As SchedulerControl)
Dim report As New XtraSchedulerReport1()
Dim dateTimeRange As DateTimeRange = scheduler.VisibleIntervals(0)
scheduler.SchedulerPrintAdapter.DateTimeRange = dateTimeRange
scheduler.SchedulerPrintAdapter.AssignToReport(report)
PrintHelper.ShowPrintPreview(mainWindow, report)
End Sub
End Class
End Namespace
You can change report elements’ appearance and content by handling the TimeCellsControlBase.AppointmentViewInfoCustomizing, TimeCellsControlBase.InitAppointmentDisplayText and TimeCellsControlBase.InitAppointmentImages events and the XtraSchedulerReport controls’ CustomDraw* event series.
Advanced users can benefit from scripting - they can write code for specific event handlers in the End-User Report Designer. See the Scripting article for more information.
See Also
How to: Print a Scheduler Using Reports from a Document Preview Window