PdfViewerControl.PrintDocumentCommand Property
Namespace: DevExpress.UI.Xaml.Controls
Assembly:
DevExpress.UI.Xaml.Controls.v21.2.dll
NuGet Package:
DevExpress.Uwp.Controls
Declaration
public ICommand PrintDocumentCommand { get; set; }
Public Property PrintDocumentCommand As ICommand
Property Value
Type |
Description |
ICommand |
A command that implements the Windows.UI.Xaml.Input.ICommand interface.
|
To learn more about using commands, refer to MSDN.
The example below illustrates a view model that implements the PrintDocumentCommand.
<dxpdf:PdfViewerControl ShowOpenDocumentButton="True"
ShowPrintDocumentButton="True"
PrintDocumentCommand="{Binding PrintDocumentCommand}"
PrintDocumentSource="{Binding PrintDocumentSource, Mode=TwoWay}"/>
public class MainViewModel : ViewModelBase {
public ICommand PrintDocumentCommand { get; private set; }
public IPrintDocumentSource PrintDocumentSource { get; set; }
CoreDispatcher dispatcher = Window.Current.Dispatcher;
public MainViewModel() {
if (ViewModelBase.IsInDesignMode)
return;
PrintDocumentCommand = new DevExpress.Mvvm.DelegateCommand(PrintDocument);
}
async void PrintDocument() {
PrintManager.GetForCurrentView().PrintTaskRequested += printManager_PrintTaskRequested;
await PrintManager.ShowPrintUIAsync();
PrintManager.GetForCurrentView().PrintTaskRequested -= printManager_PrintTaskRequested;
}
void printManager_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args) {
PrintTask printTask = null;
printTask = args.Request.CreatePrintTask("PdfViewer Demo Print Task", sourceRequested => {
printTask.Completed += async (s, e) => {
if (e.Completion == PrintTaskCompletion.Failed) {
await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () => {
await new MessageDialog("Printing error.").ShowAsync();
});
}
};
sourceRequested.SetSource(PrintDocumentSource);
});
}
}
Public Class MainViewModel
Inherits ViewModelBase
Public Property PrintDocumentCommand() As ICommand
Public Property PrintDocumentSource() As IPrintDocumentSource
Private dispatcher As CoreDispatcher = Window.Current.Dispatcher
Public Sub New()
If ViewModelBase.IsInDesignMode Then
Return
End If
PrintDocumentCommand = New DevExpress.Mvvm.DelegateCommand(AddressOf PrintDocument)
End Sub
Async Sub PrintDocument()
AddHandler PrintManager.GetForCurrentView().PrintTaskRequested, AddressOf printManager_PrintTaskRequested
Await PrintManager.ShowPrintUIAsync()
RemoveHandler PrintManager.GetForCurrentView().PrintTaskRequested, AddressOf printManager_PrintTaskRequested
End Sub
Sub printManager_PrintTaskRequested(sender As PrintManager, args As PrintTaskRequestedEventArgs)
Dim printTask As PrintTask = Nothing
printTask = args.Request.CreatePrintTask("PdfViewer Demo Print Task",
Sub(sourceRequested)
AddHandler(printTask.Completed), Async Sub(s, e)
If e.Completion = PrintTaskCompletion.Failed Then
Await dispatcher.RunAsync(CoreDispatcherPriority.Normal,
Async Sub()
Await New MessageDialog("Printing error.").ShowAsync()
End Sub)
End If
End Sub
sourceRequested.SetSource(PrintDocumentSource)
End Sub)
End Sub
End Class
See Also