Skip to main content

Override Document Preview Commands

  • 2 minutes to read

This example demonstrates how to override commands available on the WPF Document Preview toolbar. In particular, it shows how to disable the Export to PDF command.

To start with this example, create a new WPF application or open an existing one, and prepare a simple report to display in the Document Preview.

To override a command in the WPF Document Preview, do the following.

  1. Create a custom Document Preview object by inheriting from the DocumentPreviewControl class.
  2. Override methods that define logic behind the required command. For instance, to customize the Export command, override the Export and CanExport methods as shown in the sample below.

    using DevExpress.Xpf.Printing;
    using DevExpress.XtraPrinting;
    public class CustomDocumentPreviewControl : DocumentPreviewControl{
        public CustomDocumentPreviewControl() {
        public override bool CanExport(DevExpress.XtraPrinting.ExportFormat? format) {
            return format == DevExpress.XtraPrinting.ExportFormat.Pdf ? false : base.CanExport(format);
        public override void Export(DevExpress.XtraPrinting.ExportFormat? format) {
            // ...
  3. To display the customized Document Preview, create its instance in code. Specify the required Document Preview settings. To display a report, assign it to the DocumentSource property of the custom DocumentPreviewControl.

    private void ShowPreview_Click(object sender, RoutedEventArgs e) {
        CustomDocumentPreviewControl customPreview = new CustomDocumentPreviewControl();
        XtraReport1 report = new XtraReport1();
        customPreview.DocumentSource = report;
        Window newWindow = new Window();
        newWindow.Content = customPreview;
  4. Run the application to see the result.