Skip to main content
A newer version of this page is available. .

DocumentViewer.DocumentSource Property

Specifies an object that the Docuemnt Viewer converts to a document and displays. This is a dependency property.

Namespace: DevExpress.WinUI.DocumentViewer

Assembly: DevExpress.WinUI.DocumentViewer.v22.1.dll

NuGet Package: DevExpress.WinUI

Declaration

[DP(null, Handler = "OnDocumentSourceChanged")]
public object DocumentSource { get; set; }

Property Value

Type Description
Object

The document source.

Remarks

You can assign the following objects to the DocumentSource property:

Report
An object that implements the IReport interface: the XtraReport class descendants and CachedReportSource objects.
Print Link
An object that implements the ILink interface. You can use the DocumentViewer to preview, print, and export the GridControl‘s data. Refer to the following topic for more information on how to print a GridControl: Print and Export Data.
Data Stream
A Stream that contains a serialized Document.
URI
The URI of the file in PRNX format that contains the document.
String
A path to the file in PRNX format that contains the report document. If a string contains the “ms-appx:” prefix, the string is interpreted as a URI. Review the following topic for more information on report documents and PRNX files: Store Report Documents.

Note

The Reporting, DXperience, or Universal subscription is required to use an object that implements the IReport interface in your code. For pricing information, refer to the DevExpress Products matrix.

How to Preview a Report

Note

You need an active license for the Reporting, DXperience, or Universal Subscription to use the report instance in your code.

  1. Install the DevExpress.Reporting.Core NuGet package.
  2. Create an instance of the XtraReport class. You can use the LoadLayoutFromXml method to load a report layout from a .REPX file.
  3. Optional. Apply parameter values to report parameters in the XtraReport.Parameters collection.
  4. Assign the report instance to the DocumentSource property.

For more information on how to preview a report in the DocumentViewer, review the following topic: Get Started with WinUI Reporting.

Create a Report from a .REPX File

The following code sample displays a report document generated from a .REPX file in the DocumentViewer:

<Window ...
    xmlns:dxdvr="using:DevExpress.WinUI.DocumentViewer">
    <dxdvr:DocumentViewer x:Name="documentviewer" Loaded="DocumentViewer_Loaded" />
</Window>
using Microsoft.UI.Xaml;
using DevExpress.XtraReports.UI;

// ...
private async void DocumentViewer_Loaded(object sender, RoutedEventArgs e) {
    // Create an XtraReport instance.
    XtraReport report = new XtraReport();
    // Load a report layout from a .REPX file.
    report.LoadLayoutFromXml(@"C:\Invoice.repx");
    // Pass the report to the DocumentViewer.
    documentviewer.DocumentSource = report;
}

Create a Report from a Stream

The code sample below performs the following actions:

  • Gets a .REPX file (report layout) from a Uri.
  • Creates a Stream with the report layout.
  • Displays the report document that the DocumentViewer generates from the report layout.
<Window ...
    xmlns:dxdvr="using:DevExpress.WinUI.DocumentViewer">
    <dxdvr:DocumentViewer x:Name="documentviewer" Loaded="DocumentViewer_Loaded" />
</Window>
using Microsoft.UI.Xaml;
using DevExpress.XtraReports.UI;
using Windows.Storage;

private async void DocumentViewer_Loaded(object sender, RoutedEventArgs e) {
    // Create a Stream and load a .REPX file from a URI.
    var data = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///data/SampleReport.repx"));
    // Open and read the Stream.
    var stream_data = await data.OpenStreamForReadAsync();

    // Create an XtraReport instance.
    XtraReport report = new XtraReport();
    // Load a report layout from the stream.
    report.LoadLayoutFromXml(stream_data, false);
    // Pass the report to the DocumentViewer.
    documentviewer.DocumentSource = report;
}

The DocumentViewer raises the DocumentLoaded event when a document is loaded.

See Also