This example demonstrates how to customize the DocumentViewerControl toolbar.
It shows how to remove standard commands from a Ribbon toolbar, and add custom commands.
The example implements a custom command provider (DocumentCommandProvider and uses Bar Actions to modify the toolbar.
Files to Review
Documentation
More Examples
- How to Use ViewModel Data as Report Parameters in a WPF MVVM Application
- How to Use the DocumentPreviewControl in a WPF MVVM Application to Preview a Report
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
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>
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();
}
}
}