Example T263038
Visible to All Users

DocumentPreviewControl - How to Customize the Toolbar

This example demonstrates how to customize the DocumentViewerControl toolbar.
It shows how to remove standard commands from a Ribbon toolbar, and add custom commands.

Screenshot

The example implements a custom command provider (DocumentCommandProvider and uses Bar Actions to modify the toolbar.

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

MainWindow.xaml
XAML
<Window x:Class="CustomizePreviewToolbar.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" xmlns:dxp="http://schemas.devexpress.com/winfx/2008/xaml/printing" xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors" xmlns:dxb="http://schemas.devexpress.com/winfx/2008/xaml/bars" xmlns:dxpbars="http://schemas.devexpress.com/winfx/2008/xaml/printing/bars" xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon" Title="MainWindow" Height="650" Width="1100"> <Window.Resources> <DataTemplate x:Key="dayNameTemplate"> <dxe:TextEdit IsPrintingMode="True" Text="{Binding Path=Content}"/> </DataTemplate> </Window.Resources> <Grid> <dxp:DocumentPreviewControl Name="preview"> <dxp:DocumentPreviewControl.CommandProvider> <dxp:DocumentCommandProvider> <dxp:DocumentCommandProvider.RibbonActions> <dxb:UpdateAction ElementName="{x:Static dxpbars:DefaultPreviewBarItemNames.Print}" Property="{x:Static dxb:BarItem.LargeGlyphProperty}" Value="{dxp:PrintingResourceImage ResourceName='Images/BarItems/Print.svg'}"/> <dxb:RemoveAction ElementName="{x:Static dxpbars:DefaultPreviewBarItemNames.Export}"/> <dxb:RemoveAction ElementName="{x:Static dxpbars:DefaultPreviewBarItemNames.Send}"/> <dxb:RemoveAction ElementName="{x:Static dxpbars:DefaultPreviewBarItemNames.FileGroup}"/> <dxb:InsertAction> <dxb:InsertAction.Element> <dxr:RibbonPageGroup Caption="Custom Commands" Name="CustomCommandGroup"/> </dxb:InsertAction.Element> </dxb:InsertAction> <dxb:InsertAction ContainerName="CustomCommandGroup"> <dxb:InsertAction.Element> <dxb:BarButtonItem Content="Create Document" ItemClick="CreateDocument_ItemClick"/> </dxb:InsertAction.Element> </dxb:InsertAction> <dxb:InsertAction ContainerName="CustomCommandGroup"> <dxb:InsertAction.Element> <dxb:BarButtonItem Content="Clear Preview" ItemClick="ClearPreview_ItemClick" /> </dxb:InsertAction.Element> </dxb:InsertAction> <dxb:InsertAction ContainerName="{x:Static dxpbars:DefaultPreviewBarItemNames.ExportGroup}"> <dxb:InsertAction.Element> <dxb:BarButtonItem Content="{dxp:PrintingStringId StringId=ExportPdf}" LargeGlyph="{dxp:PrintingResourceImage ResourceName='Images/BarItems/ExportPDF.svg'}" Glyph="{dxp:PrintingResourceImage ResourceName='Images/BarItems/ExportPDF.svg'}" Hint="{dxp:PrintingStringId StringId=ExportPdf}" Command="{Binding Path=(dxp:DocumentPreviewControl.ActualViewer).ExportCommand, RelativeSource={RelativeSource Self}}" CommandParameter="Pdf"/> </dxb:InsertAction.Element> </dxb:InsertAction> </dxp:DocumentCommandProvider.RibbonActions> </dxp:DocumentCommandProvider> </dxp:DocumentPreviewControl.CommandProvider> </dxp:DocumentPreviewControl> </Grid> </Window>
MainWindow.xaml.cs(vb)
C#
using System.Globalization; using System.Windows; using DevExpress.Xpf.Printing; namespace CustomizePreviewToolbar { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { private SimpleLink link; public MainWindow() { InitializeComponent(); // Creates a document to display. string[] data = CultureInfo.CurrentCulture.DateTimeFormat.DayNames; link = new SimpleLink { DetailTemplate = (DataTemplate)Resources["dayNameTemplate"], DetailCount = data.Length }; link.CreateDetail += (s, e) => e.Data = data[e.DetailIndex]; preview.DocumentSource = link; link.CreateDocument(); } private void CreateDocument_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e) { link.CreateDocument(); } private void ClearPreview_ItemClick(object sender, DevExpress.Xpf.Bars.ItemClickEventArgs e) { link.PrintingSystem.ClearContent(); } } }

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.