首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >检测FixedPage上的内容是否超过了底部边界

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

Stack Overflow用户
提问于 2018-07-30 17:17:30
回答 1查看 140关注 0票数 0

我正在创建一份我想稍后打印的文档。此文档将包含一个网格,该网格将列出像表一样的项,包括标题行。项目的数量是不同的,因此网格有可能超过单个页面的底部边界。当发生这种情况时,我想在第二页继续,“表”标题将再次出现在它上。我正在用程序将行添加到一个for-循环中。

您知道如何检测是否超过了底部的页面边界吗?也许有另一种方法。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-03 17:33:28

解决方案是将StackPanel作为每个FixedPage的“根子”。然后,我可以添加内容并测量它。

代码语言:javascript
复制
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的定义如下:

代码语言:javascript
复制
double MaxPageContentHeight = PageHeight - Margin.Top - Margin.Bottom;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51599207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档