2

これが状況です。

私は、さまざまな高さと一定の(フルページ)幅の多数の異なるセクションで構成されるかなり大きなドキュメントを自動生成する必要があります。

各セクションは、2つの異なるサブセクションで構成されています。それらを「ヘッダー」および「データ」と考えてください。

問題は次のとおりです。1つのセクションだけがページに収まる場合(データが多いため)、ヘッダーは一番上に表示され、データは一番下に表示され、未使用のスペースは中央に残されます。

1つのページに複数のセクションが収まる場合は、すべてが「一番上まで押しつぶされ」、サブセクション間、さらにはセクション間にスペースを残さないようにする必要があります。余分な空白はすべて下部にあるはずです。

これを達成するためにどのような種類の構成を使用できますか?

おそらく、これはFixedDocumentにより適したタスクですか?私はWPFに関するかなり大きな本を持っていますが、FixedDocumentsについてはほとんど言及していません。

4

1 に答える 1

2

この問題とまだ闘っているのかどうかはわかりませんが、FlowDocumentを使用してみることができます。

DocumentPaginatorのラッパーを作成すると、flowdocにヘッダーを挿入できるようになります。また、printablePageHeightとコンテンツサイズの高さを考慮して、flowdoc.PagePaddingをカスタム値に設定できます。

これは、私が本から入手したDocumentPaginatorのラッパーの例です:C#2008のPro WPF-Mathew MacDonald

それが役に立てば幸い。(追記。デフォルトをコピーして貼り付けただけなので、カスタム計算などは追加しませんでした。)

using System.Globalization;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;

namespace NPS.ClinicalEAudit.Controls
{

    public class FlowDocPaginator : DocumentPaginator
    {
        private DocumentPaginator _paginator;

        public FlowDocPaginator(FlowDocument flowDoc)
        {
            _paginator = ((IDocumentPaginatorSource) flowDoc).DocumentPaginator;

        }

        public override bool IsPageCountValid
        {
            get { return _paginator.IsPageCountValid; }
        }

        public override int PageCount
        {
            get { return _paginator.PageCount; }
        }

        public override Size PageSize
        {
            get { return _paginator.PageSize; }
            set { _paginator.PageSize = value; }
        }

        public override IDocumentPaginatorSource Source
        {
            get { return _paginator.Source; }
        }

        public override DocumentPage GetPage(int pageNumber)
        {
            // Get the requested page.
            DocumentPage page = _paginator.GetPage(pageNumber);

            // Wrap the page in a Visual object. You can then apply transformations
            // and add other elements.
            ContainerVisual newVisual = new ContainerVisual();
            newVisual.Children.Add(page.Visual);

            // Create a header.
            DrawingVisual header = new DrawingVisual();

            using (DrawingContext dc = header.RenderOpen())
            {
                Typeface typeface = new Typeface("Times New Roman");
                FormattedText text = new FormattedText("Page " +
                                                       (pageNumber + 1).ToString(), CultureInfo.CurrentCulture,
                                                       FlowDirection.LeftToRight, typeface, 14, Brushes.Black);

                // Leave a quarter inch of space between the page edge and this text.
                dc.DrawText(text, new Point(96 * 0.25, 96 * 0.25));
            }

            // Add the title to the visual.
            newVisual.Children.Add(header);

            // Wrap the visual in a new page.
            DocumentPage newPage = new DocumentPage(newVisual);
            return newPage;
        }

    }
}
于 2010-10-19T02:48:36.560 に答える