简体   繁体   English

检测FixedPage上的内容是否超过底部边界

[英]Detect if content on FixedPage exceeds bottom boundary

I'm creating a document I'd like to print later. 我正在创建一个文档,稍后再打印。 This document shall contain a grid that lists items like a table, including a header row. 该文档应包含一个网格,该网格列出诸如表的项目,包括标题行。 The number of items varies and therefore it is possible that the grid exceeds the bottom boundary of a single page. 项目的数量各不相同,因此网格可能会超出单个页面的底部边界。 When that happens, I'd like to continue on a second page, the "table" header shall be on it again. 发生这种情况时,我想继续在第二页上,“ table”标题将再次位于该页上。 I 'm adding the rows programatically in a for-loop. 我正在以编程方式在for循环中添加行。

Do you know a way how to detect if the bottom page boundary is exceeded? 您知道一种如何检测是否超出底部边界的方法吗? Maybe there's a different approach. 也许有不同的方法。

The Solution is to take a StackPanel as the "root child" for each FixedPage. 解决方案是将StackPanel作为每个FixedPage的“根子”。 I then can add content and measure it. 然后,我可以添加内容并对其进行度量。

public StackPanel AddNewPage()
{
    PageContent pC = new PageContent();
    FixedPage fP = new FixedPage { Width = PageWidth, Height = PageHeight, Margin = Margin };

    StackPanel sP = new StackPanel { Width = PageWidth - Margin.Left - Margin.Right };
    fP.Children.Add(sP);

    pC.Child = fP;

    //FixedDocument
    Document.Pages.Add(pC);

    //used later to add content to the page 
    return sP;
}

public bool IsPageOverfilled(int pageIndex)
{
    StackPanel sP = (Document.Pages[pageIndex].Child as FixedPage).Children[0] as StackPanel;
    //necessary to recognize new added elements
    sP.UpdateLayout();
    sP.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

    if (sP.DesiredSize.Height > MaxPageContentHeight)
        return true;
    else return false;
}

MaxPageContentHeight is defined as the following: MaxPageContentHeight定义如下:

double MaxPageContentHeight = PageHeight - Margin.Top - Margin.Bottom;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM