xtrareports-117751-desktop-reporting-wpf-reporting-wpf-reporting-document-preview-quick-start-create-a-custom-document-preview.md
This topic describes how to add the DocumentPreviewControl to a WPF application to preview a report.
Do the following to add the DocumentPreviewControl to your application:
Create a new WPF application from the DevExpress template.
Add a new XtraReport1 report to the project. For more information, review the following help topic: Create a Report in Visual Studio.
Implement the ViewModel class and pass an instance of this class as the data context:
Open the MainWindow.xaml file in the Visual Studio Designer and drop the DocumentPreviewControl from the DX.25.2: Reporting Toolbox tab to the design surface:
The MainWindow.xaml file contains the following XAML content:
Run the application.
If a report contains more than 1000 pages, bind the DocumentPreviewControl to the CachedReportSource component to reduce memory usage. This component stores document pages in a file system or database during document generation.
Call the CachedReportSource object’s CreateDocumentAsync() method to generate a document for preview.
using DevExpress.Xpf.Printing;
using DevExpress.XtraPrinting.Caching;
// ...
private void Window_Loaded(object sender, System.Windows.RoutedEventArgs e) {
var storage = new MemoryDocumentStorage();
var report = new XtraReport1();
var cachedReportSource = new CachedReportSource(report, storage);
documentPreview1.DocumentSource = cachedReportSource;
cachedReportSource.CreateDocumentAsync();
}
Imports DevExpress.Xpf.Printing
Imports DevExpress.XtraPrinting.Caching
' ...
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs)
Dim storage = New MemoryDocumentStorage()
Dim report = New XtraReport1()
Dim cachedReportSource = New CachedReportSource(report, storage)
documentPreview1.DocumentSource = cachedReportSource
cachedReportSource.CreateDocumentAsync()
End Sub
The MemoryDocumentStorage object in this code snippet compresses data and stores the report document in memory. You can use file storage (the FileDocumentStorage object), database storage (the DbDocumentStorage object), or implement a custom storage instead.
See Also