예제 #1
0
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog   printDialog = new PrintDialog();
            PageMediaSize pageSize    = new PageMediaSize(PageMediaSizeName.ISOA4);

            printDialog.PrintTicket.PageMediaSize   = pageSize;
            printDialog.PrintTicket.PageOrientation = System.Printing.PageOrientation.Landscape;

            bool?pdResult = printDialog.ShowDialog();

            if (pdResult != null && pdResult.Value)
            {
                try
                {
                    FixedDocument document;
                    if (dgResult.SelectedItems.Count > 0)
                    {
                        List <Catlouge> existingList  = (dgResult.ItemsSource as List <Catlouge>).ToList();
                        List <Catlouge> selectedItems = new List <Catlouge>();
                        foreach (var item in dgResult.SelectedItems)
                        {
                            selectedItems.Add(item as Catlouge);
                        }

                        dgResult.ItemsSource = selectedItems;
                        dgResult.UpdateLayout();

                        document = PrintHelper.CreateFixedDocument(dgResult, "Header", 30, 50);
                        printDialog.PrintDocument(document.DocumentPaginator, "Search Results");

                        dgResult.ItemsSource = existingList;
                        dgResult.UpdateLayout();
                    }
                    else
                    {
                        document = PrintHelper.CreateFixedDocument(dgResult, "Header", 30, 50);
                        printDialog.PrintDocument(document.DocumentPaginator, "Search Results");
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + " : " + ex.InnerException);
                }
            }
        }