0

動作しているstackpanelsを使用してデータ列ヘッダーを印刷しようとしましたが、印刷物が得られました。唯一の問題は、固定幅の後にスタックパネルが途切れてしまい、どのプロパティがそれを担当しているのかわからないことです。プリンターは、スタックパネルよりも幅が短いスタックパネルの長方形の制限のみを認識し、長方形の中にあるものだけを印刷するようです。写真がないとうまく説明できませんが、私はスキャナーを持っていません。

私のコードは次のとおりです。

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. 

21、22、23、ヘッダーはありません。

4

0 に答える 0