/// <summary>
        /// Prints the report content.  This method is invoked by the PrintCommand.
        /// </summary>
        public void Print()
        {
            const double Inch = 96;

            // Create a PrintDialog
            System.Windows.Controls.PrintDialog printDlg = new System.Windows.Controls.PrintDialog();

            // Create IDocumentPaginatorSource from a copy of our flowdocument content
            MemoryStream stream         = new MemoryStream();
            TextRange    sourceDocument = new TextRange(Content.ContentStart, Content.ContentEnd);

            sourceDocument.Save(stream, System.Windows.DataFormats.Xaml);

            FlowDocument flowDocumentCopy  = new FlowDocument();
            TextRange    copyDocumentRange = new TextRange(flowDocumentCopy.ContentStart, flowDocumentCopy.ContentEnd);

            copyDocumentRange.Load(stream, System.Windows.DataFormats.Xaml);

            double xMargin = (1.25 * Inch);
            double yMargin = (1 * Inch);

            // Set the page padding
            flowDocumentCopy.PagePadding = new Thickness(yMargin, xMargin, xMargin, yMargin);

            IDocumentPaginatorSource idpSource = flowDocumentCopy;

            try
            {
                // Call PrintDocument method to send document to printer
                printDlg.PageRangeSelection   = PageRangeSelection.AllPages;
                printDlg.UserPageRangeEnabled = true;
                if (printDlg.ShowDialog() == true)
                {
                    printDlg.PrintDocument(idpSource.DocumentPaginator, Title);
                    this.OnRequestClose();
                }
            }
            catch (Exception printError)
            {
                WPFMessageBox.Show(Properties.Resources.Error_Encountered, Properties.Resources.CannotPrint + " " + printError.Message, WPFMessageBoxButtons.OK, WPFMessageBoxImage.Error);
            }
        }
Exemplo n.º 2
0
 protected override bool ShouldClose()
 {
     return(IsSaved || WPFMessageBox.Show("Confirm Cancel", "Cancel without saving changes?", WPFMessageBoxButtons.YesNo, WPFMessageBoxImage.Question) == WPFMessageBoxResult.Yes);
 }