Back to Devexpress

How to: Customize the Document Preview Toolbar

wpf-9655-controls-and-libraries-printing-exporting-examples-how-to-customize-the-document-preview-toolbar.md

latest2.4 KB
Original Source

How to: Customize the Document Preview Toolbar

  • Jan 28, 2022
  • 3 minutes to read

View Example

This example demonstrates how you can customize the Document Preview toolbar. You can remove standard toolbar controls, and add custom commands and controls.

Proceed as follows:

  1. In XAML, use the CommandProvider property to declare the DocumentCommandProvider as a custom command provider for the Document Preview control. A command provider exposes the RibbonActions property, which allows you to access a collection of actions for the Document Preview control’s Ribbon. You should create Bar Actions and add them to the CommandProvider.RibbonActions collection:

  2. The UpdateAction can replace a toolbar command’s standard icon. To identify a toolbar item by name, use the DefaultPreviewBarItemNames class. The following code uses the UpdateAction to change the Print command icon:

  3. The RemoveAction can remove an element from a toolbar. The following code removes the File , Send , and Export command groups:

  4. The InsertAction can add a new element to the toolbar. The following code adds a new command group with two buttons ( Create Document and Clear Preview ):

  5. Add a custom Export to PDF button to allow a user to export to PDF:

  6. In this example, the Document Viewer loads a document created at runtime to display data from a simple array. The SimpleLink instance gets data from an array and uses the dayNameTemplate defined in XAML to create a document:

  7. Handle the BarItem.ItemClick events for the newly added buttons:

The result is shown in the following image: