Skip to main content

PdfViewerControl.PrintDocumentSource Property

Gets or sets the source for the print document. This is a dependency property.

Namespace: DevExpress.UI.Xaml.Controls

Assembly: DevExpress.UI.Xaml.Controls.v21.2.dll

NuGet Package: DevExpress.Uwp.Controls

#Declaration

public IPrintDocumentSource PrintDocumentSource { get; set; }

#Property Value

Type Description
IPrintDocumentSource

An object implementing the IPrintDocumentSource interface.

#Remarks

The example below illustrates a view model that implements the PdfViewerControl.PrintDocumentCommand.

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);
            });
        }

    }
See Also