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

DocumentViewer Class

A control that allows you to preview, print, save, and export a GridControl‘s data or reports created with the DevExpress Reports Suite.

Namespace: DevExpress.WinUI.DocumentViewer

Assembly: DevExpress.WinUI.DocumentViewer.v21.2.dll

Declaration

public class DocumentViewer :
    Control,
    IXamlRootProvider

Remarks

DocumentViewer - GUI

Supported Objects

You can use the DocumentViewer to preview, print, save, and export the following files and objects:

Objects implementing the IReport interface

A report layout.

A Reporting, DXperience, or Universal subscription is required to display an object that implements the IReport interface in the DocumentViewer. For pricing information, refer to the DevExpress Products matrix.

Refer to the following topic for more information on how to create a report layout: Create a Report in Visual Studio

Objects that implement the ILink interface

You can use the DocumentViewer to preview, print, and export GridControl‘s data.

Refer to the following topic for more information on how to print a GridControl Print and Export Data

Report Documents (.PRNX file)

A report document that is built from a report layout.

Refer to the following topic for more information on the .PRNX files: Store Report Documents

In the DocumentViewer, all the available objects and files described above are called a document.

Display Documents

Use the DocumentSource property to display a document in the DocumentViewer.

Save Documents

Call the Save(String) method to save the opened document to a .PRNX file at the specified location.

You can also use the ShowSaveDialogCommand or click the Save As button in the toolbar to open the Save As dialog.

Export Documents

Call the Export(ExportFormats, String) method to export the opened document. Pass a file format as the first parameter and the file path as second parameter.

You can also use the ShowExportDialogCommand or click the Export button in the toolbar to open the Export dialog.

You can export the opened document to the following formats:

Call the ShowPrintDialogCommand or click the Print button in the toolbar to open the Print dialog.

Specify and View IReport Parameters

Set the ShowParameters property to true to display the Parameters panel.

You can also use the ToggleReportParameterPanelCommand or click the Parameters button in the toolbar to open the Parameters panel.

The DevExpress Report Suite’s API allows you to specify a .REPX parameter value. Refer to the following topic for more information on report parameters: Specify Parameter Values.

Create a Custom Toolbar

To create a DocumentViewer‘s custom command bar items, set the ShowCommandBar property to false and define a CommandBar in XAML prior to the DocumentViewer instance.

View Example: WinUI DocumentViewer - Create a Custom Toolbar

The following code creates a custom toolbar with the standard DocumentViewer‘s commands and adds the Back and Close AppBarButtons and a link to this documentation page (a HyperlinkButton inside the AppBarElementContainer ):

<Page ...
    xmlns:dxdv="using:DevExpress.WinUI.DocumentViewer">
    <Grid RowDefinitions="Auto,*">
        <CommandBar HorizontalAlignment="Left" IsOpen="False" DefaultLabelPosition="Right">
            <AppBarButton Click="AppBarButton_Click">
                <FontIcon Glyph="&#xE72B;"  />
            </AppBarButton>
            <AppBarSeparator/>
            <AppBarButton Label="Open..." Command="{x:Bind documentViewer.Commands.ShowOpenDialogCommand}">
                <FontIcon Glyph="&#xED25;"  />
            </AppBarButton>
            <AppBarButton Label="Save As..." Command="{x:Bind documentViewer.Commands.ShowSaveDialogCommand}">
                <FontIcon Glyph="&#xE74E;"/>
            </AppBarButton>
            <AppBarButton Label="Print..." Command="{x:Bind documentViewer.Commands.ShowPrintDialogCommand}">
                <FontIcon Glyph="&#xE749;" />
            </AppBarButton>

            <AppBarElementContainer VerticalContentAlignment="Center">
                <StackPanel Orientation="Horizontal" Spacing="5" Margin="8,0">
                    <TextBlock Text="Zoom" FontSize="12" VerticalAlignment="Center" Margin="5,11,4,12"/>
                    <ComboBox Padding="10,-2,0,0" IsEnabled="False" SelectedIndex="2" Width="78" FontSize="12"
                              VerticalAlignment="Center" VerticalContentAlignment="Center">
                        <ComboBox.Items>
                            <ComboBoxItem Content="50%" Tag="50"/>
                            <ComboBoxItem Content="75%" Tag="75"/>
                            <ComboBoxItem Content="100%" Tag="100"/>
                            <ComboBoxItem Content="125%" Tag="125"/>
                            <ComboBoxItem Content="150%" Tag="150"/>
                            <ComboBoxItem Content="175%" Tag="175"/>
                            <ComboBoxItem Content="200%" Tag="200"/>
                            <ComboBoxItem Content="225%" Tag="225"/>
                            <ComboBoxItem Content="250%" Tag="250"/>
                        </ComboBox.Items>
                    </ComboBox>
                </StackPanel>
            </AppBarElementContainer>

            <AppBarButton Label="Export..." Command="{x:Bind documentViewer.Commands.ShowExportDialogCommand}">
                <FontIcon Glyph="&#xEE71;" />
            </AppBarButton>
            <AppBarToggleButton Label="Parameters" Command="{x:Bind documentViewer.Commands.ToggleReportParameterPanelCommand}">
                <FontIcon Glyph="&#xF8A6;" />
            </AppBarToggleButton>
            <AppBarButton Icon="Cancel" Label="Close" Command="{x:Bind documentViewer.Commands.CloseDocumentCommand}">
                <FontIcon Glyph="&#xE8BB;" />
            </AppBarButton>
            <AppBarSeparator/>
            <AppBarElementContainer Height="30">
                <HyperlinkButton NavigateUri="https://docs.devexpress.com/WinUI/DevExpress.WinUI.DocumentViewer.DocumentViewer" Content="Documentation"/>
            </AppBarElementContainer>
        </CommandBar>
        <dxdv:DocumentViewer x:Name="documentViewer" ShowCommandBar="False" Grid.Row="1"/>
    </Grid>
</Page>

Visual Elements

The DocumentViewer contains of the following UI elements:

DocumentViewer - GUI

API

The DocumentViewer includes the following properties, methods, events, and commands:

Member

Description

DocumentSource

Gets or sets the DocumentViewer‘s document source. This is a dependency property.

Save(String)

Saves the opened document to the specified file.

Export(ExportFormats, String)

Exports the document with the specified name, path, and file format.

Commands

Provides access to DocumentViewer commands.

CurrentPageIndex

Gets or sets the index of the current page. This is a dependency property.

PageCount

Gets the total number of pages in the opened document.

ShowCommandBar

Gets or sets whether to show a DocumentViewer‘s command bar. This is a dependency property.

ZoomFactor

Gets or sets the opened document’s zoom factor. This is a dependency property.

DocumentLoaded

Occurs after the DocumentViewer loads a document.

Commands

Each of the DocumentViewer‘s Commands (except the CloseDocumentCommand) is bound to a UI element.

Document Navigation Commands

Command

Description

Bound UI Element

FirstPageCommand

Gets or sets the command that navigates to the first page of the document.

WinUI DocumentViewer | FirstPage Button

GoToPageCommand

Gets or sets the command that navigates to a specific page of the document.

WinUI DocumentViewer | GoToPage Button

LastPageCommand

Gets or sets the command that navigates to the last page of the document.

WinUI DocumentViewer | LastPage Button

NextPageCommand

Gets or sets the command that navigates to the next page.

WinUI DocumentViewer | NextPage Button

PrevPageCommand

Gets or sets the command that navigates to the previous page.

WinUI DocumentViewer | PrevPage Button

Dialog Commands

Command

Description

Bound UI Element

ShowExportDialogCommand

Gets or sets the command that opens the Export dialog.

WinUI DocumentViewer | Export Button

ShowOpenDialogCommand

Gets or sets the command that opens the Open File dialog.

WinUI DocumentViewer | Open Button

ShowPrintDialogCommand

Gets or sets the command that opens the Print File dialog.

WinUI DocumentViewer | Print Button

ShowSaveDialogCommand

Gets or sets the command that opens the Save File dialog.

WinUI DocumentViewer | Save Button

Miscellaneous Commands

Command

Description

Bound UI Element

CloseDocumentCommand

Gets or sets the command that closes the document in the DocumentViewer.

ToggleReportParameterPanelCommand

Gets or sets the command that toggles the visibility of the Report Parameter Panel that displays the current .REPX document’s parameters.

WinUI DocumentViewer | Parameters Button

ZoomCommand

Gets or sets the command that changes the zoom factor.

WinUI DocumentViewer | Zoom Combobox

See Also