The requested page is not available for the requested platform. You are viewing the content for Default platform.

Override Document Preview Commands

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) {
            // ...
            base.Export(format);
        }
    }
    
  3. To display the customized Document Preview, create its instance in code. Specify the required Document Preview settings and assign the report to display.

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

    WpfDocumentpreview_OverrideCommandResult