1 回答
TA贡献1847条经验 获得超7个赞
解决方案是将 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;
- 1 回答
- 0 关注
- 186 浏览
添加回答
举报