wpf-120325-controls-and-libraries-printing-exporting-concepts-backstage-print-preview.md
The BackstagePrintPreview control replicates the Print screen from Microsoft Office applications. This control can be incorporated into a Backstage View-based menu. The Backstage Print Preview displays its source document’s preview on the right side and various print options on the left side.
Use the BackstageTabItem class to integrate the Backstage Print Preview into the BackstageViewControl. Specify the RibbonControl.ApplicationMenu property to attach the Backstage View to the RibbonControl as demonstrated below.
<Window Title="Backstage Print Preview" Height="350" Width="525"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxp="http://schemas.devexpress.com/winfx/2008/xaml/printing"
xmlns:dxr="http://schemas.devexpress.com/winfx/2008/xaml/ribbon" x:Class="BackstagePrintPreview.MainWindow">
<dxr:RibbonControl RibbonStyle="Office2010" VerticalAlignment="Stretch">
<dxr:RibbonPage Caption="My Page">
<dxr:RibbonPageGroup Caption="My Group"/>
</dxr:RibbonPage>
...
<dxr:RibbonControl.ApplicationMenu>
<dxr:BackstageViewControl>
<dxr:BackstageTabItem Content="Print">
<dxp:BackstagePrintPreview Margin="40,40,0,0" DocumentSource="{Binding DocumentSource}" />
</dxr:BackstageTabItem>
</dxr:BackstageViewControl>
</dxr:RibbonControl.ApplicationMenu>
</dxr:RibbonControl>
</Window>
The BackstagePrintPreview.DocumentSource property allows you to provide the document source to the Backstage Print Preview. This control supports the following document source types:
You can use the BackstagePrintPreview.ShowPrintSettings property to specify whether to display the predefined print settings. The BackstagePrintPreview.ShowPreview property enables you to control the preview area’s visibility.
You can also use the BackstagePrintPreview.CustomSettings property as shown below to add custom options to the Backstage Print Preview.
<Window ...
Title="MainWindow" DataContext="{dxmvvm:ViewModelSource Type=local:ViewModel}">
<Window.Resources>
<DataTemplate DataType="{x:Type local:CustomSettingsViewModel}">
<StackPanel>
<TextBlock Text="Custom Settings" FontSize="20" Margin="0,0,0,12" />
<dxe:CheckEdit IsChecked="{Binding ShowSubordinates}" Content="Show Subordinates" />
</StackPanel>
</DataTemplate>
</Window.Resources>
<dxr:RibbonControl RibbonStyle="Office2010">
...
<dxr:RibbonControl.ApplicationMenu>
<dxr:BackstageViewControl>
<dxr:BackstageTabItem Content="Print">
<dxp:BackstagePrintPreview Margin="40,40,0,0" DocumentSource="{Binding DocumentSource}"
ShowPrintSettings="False" CustomSettings="{Binding CustomSettings}" />
</dxr:BackstageTabItem>
</dxr:BackstageViewControl>
</dxr:RibbonControl.ApplicationMenu>
</dxr:RibbonControl>
</Window>
ViewModel:
using System.ComponentModel;
using DevExpress.Mvvm.POCO;
using DevExpress.XtraReports.UI;
public class ViewModel {
public virtual XtraReport DocumentSource { get; protected set; }
public CustomSettingsViewModel CustomSettings { get; }
protected ViewModel() {
CustomSettings = ViewModelSource.Create(() => new CustomSettingsViewModel());
((INotifyPropertyChanged)CustomSettings).PropertyChanged += OnCustomSettingsChanged;
}
void OnCustomSettingsChanged(object sender, PropertyChangedEventArgs e) {
// Insert your custom logic here.
// ...
}
}
public class CustomSettingsViewModel {
public virtual bool ShowSubordinates { get; set; }
public CustomSettingsViewModel() {
ShowSubordinates = true;
}
}
Imports System.ComponentModel
Imports DevExpress.Mvvm.POCO
Imports DevExpress.XtraReports.UI
Public Class ViewModel
Public Overridable Property DocumentSource As XtraReport
Public ReadOnly Property CustomSettings As CustomSettingsViewModel
Protected Sub New()
CustomSettings = ViewModelSource.Create(Function() New CustomSettingsViewModel())
(CType(CustomSettings, INotifyPropertyChanged)).PropertyChanged += AddressOf OnCustomSettingsChanged
End Sub
Private Sub OnCustomSettingsChanged(ByVal sender As Object, ByVal e As PropertyChangedEventArgs)
' Insert your custom logic here.
' ...
End Sub
End Class
Public Class CustomSettingsViewModel
Public Overridable Property ShowSubordinates As Boolean
Public Sub New()
ShowSubordinates = True
End Sub
End Class
The following image demonstrates the result: