我正在创建一份我想稍后打印的文档。此文档将包含一个网格,该网格将列出像表一样的项,包括标题行。项目的数量是不同的,因此网格有可能超过单个页面的底部边界。当发生这种情况时,我想在第二页继续,“表”标题将再次出现在它上。我正在用程序将行添加到一个for-循环中。
您知道如何检测是否超过了底部的页面边界吗?也许有另一种方法。
发布于 2018-08-03 17:33:28
解决方案是将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;https://stackoverflow.com/questions/51599207
复制相似问题