wpf-9655-controls-and-libraries-printing-exporting-examples-how-to-customize-the-document-preview-toolbar.md
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:
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:
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:
The RemoveAction can remove an element from a toolbar. The following code removes the File , Send , and Export command groups:
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 ):
Add a custom Export to PDF button to allow a user to export to PDF:
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:
Handle the BarItem.ItemClick events for the newly added buttons:
The result is shown in the following image: