在打印输出中看不到完整的stackpanel

时间:2013-04-25 18:09:23

标签: c# wpf events printing

我一直在尝试使用正在运行的stackpanel打印我的数据列标题,然后我得到了我的打印输出。唯一的问题是我的stackpanel在固定宽度后被切断,我不确定哪个属性负责它。这就像打印机只在我的堆栈面板上看到一个矩形限制,它的宽度比我的stackpanel短,只打印矩形中的内容。没有图片我无法真正解释它,但我没有扫描仪。

以下是我的代码:

private void btnPrint_Click(object sender, RoutedEventArgs e)
    {
        PrintDialog dialog = new PrintDialog();
        if (dialog.ShowDialog().GetValueOrDefault())
        {
            List<Result> results = vm.ObsResults.OrderByDescending(r => Convert.ToDouble(r.SchedulingRate)).ToList();
            var propList = typeof(Result).GetProperties().ToList();
            int maxRowsPerPage = 42;

            var pgCnt = results.Count / maxRowsPerPage;

            XpsDocumentWriter docWriter = PrintQueue.CreateXpsDocumentWriter(dialog.PrintQueue);
            PrintTicket ticket = new PrintTicket();
            ticket.PageOrientation = PageOrientation.Landscape;

            for (int pgNum = 0; pgNum <= pgCnt; pgNum++)
            {
                //Title
                Canvas c = new Canvas();
                c.Width = 1024;
                c.Height = 768;
                TextBlock tbTitle = new TextBlock();
                tbTitle.Text = " Results " + vm.ObsDate.ToString("MM/dd/yyyy");
                tbTitle.FontSize = 16;
                Canvas.SetLeft(tbTitle, 20);
                Canvas.SetTop(tbTitle, 10);
                c.Children.Add(tbTitle);

                //Column Headers
                StackPanel sp = new StackPanel() { Orientation = Orientation.Horizontal , Width = 885};
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "Unit Name", Width = 150, Background = new SolidColorBrush(Colors.LightBlue) }});
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "Unit ID", Width = 65, Background = new SolidColorBrush(Colors.LightBlue) }});
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "Schedule", Width = 65, Background = new SolidColorBrush(Colors.LightBlue) }});
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "TPS", Width = 25, Background = new SolidColorBrush(Colors.LightBlue) }});
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "TTS", Width = 35, Background = new SolidColorBrush(Colors.LightBlue) }});
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "Min Run", Width = 50, Background = new SolidColorBrush(Colors.LightBlue) }});
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "Schd RT", Width = 50, Background = new SolidColorBrush(Colors.LightBlue) }});
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "MW", Width = 35, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "00", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "01", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "02", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "03", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "04", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "05", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "06", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "07", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "08", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "09", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "10", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "11", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "12", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "13", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "14", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "15", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "16", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "17", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "18", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "19", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "20", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "21", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "22", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 0, 1), Child = new TextBlock() { Text = "23", Width = 15, TextAlignment = TextAlignment.Center, Background = new SolidColorBrush(Colors.LightBlue) } });
                sp.Children.Add(new Border() { BorderBrush = new SolidColorBrush(Colors.LightGray), BorderThickness = new Thickness(1, 1, 1, 1), Child = new TextBlock() { Text = "Constraint", Width = 100, Background = new SolidColorBrush(Colors.LightBlue) } });
                Canvas.SetLeft(sp, 20);
                Canvas.SetTop(sp, 35);
                c.Children.Add(sp);

                int idxStart = pgNum * maxRowsPerPage;
                int idxEnd = Math.Min(results.Count, idxStart + maxRowsPerPage);

                int topMargin = 3;

               }
                c.Measure(new Size(Int32.MaxValue, Int32.MaxValue));
                c.Arrange(new Rect(new Point(0, 0), c.DesiredSize));

                FixedPage fxdPg = new FixedPage();
                fxdPg.Children.Add(c);
                PageContent pgContent = new PageContent();
                ((IAddChild)pgContent).AddChild(fxdPg);
                fxdDoc.Pages.Add(pgContent);
            }

            docWriter.WriteAsync(fxdDoc, ticket);
        }
    }

它看起来像是被切断的地方:

00 | 01 | 02 | ... |18 | 19 | 2/  <cut off. 

No 21,22,23,header。

0 个答案:

没有答案