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

我正在创建一个我想稍后打印的文档。该文件应包含一个网格,列出类似表格的项目,包括标题行。项目数量各不相同,因此网格可能会超出单个页面的底部边界。发生这种情况时,我想在第二页上继续,“表格”标题将再次出现。我在 for 循环中以编程方式添加行。

您知道如何检测是否超出底部页面边界的方法吗?也许有不同的方法。


汪汪一只猫
浏览 173回答 1
1回答

aluckdog

解决方案是将 StackPanel 作为每个 FixedPage 的“根子级”。然后我可以添加内容并进行测量。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 定义如下:double MaxPageContentHeight = PageHeight - Margin.Top - Margin.Bottom;
打开App,查看更多内容
随时随地看视频慕课网APP