首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在WPF中将PageContent/ FixedPage添加到FixedDocument的正确方法是什么?

在WPF中将PageContent/ FixedPage添加到FixedDocument的正确方法是什么?
EN

Stack Overflow用户
提问于 2013-03-07 09:36:46
回答 1查看 9.9K关注 0票数 10

在WPF中,要将FixedPage添加到代码中的FixedDocument中,需要:

代码语言:javascript
复制
var page = new FixedPage();
var pageContent = new PageContent();

((IAddChild)pageContent).AddChild(page);

然而,这似乎是唯一的办法:

  • MSDN文档明确表示不应该这样做(“此API支持.NET框架基础设施,不打算直接从代码中使用。”- PageContent.IAddChild.AddChild法)。
  • 为了将内容添加到PageContent中,必须强制转换到显式接口实现是很难看的。
  • 执行PageContent的基本操作并不简单。

这些文档实际上并没有解释如何做到这一点,我也找不到任何其他关于如何做到这一点的信息。还有别的办法吗?正确的方式?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-04-09 19:16:23

根据MSDN文档,只需将一个FixedPage对象添加到PageContent.Child属性中,然后通过调用FixedDocument.Pages.Add方法将其添加到FixedDocument中。

例如:

代码语言:javascript
复制
public FixedDocument RenderDocument() 
{
    FixedDocument fd = new FixedDocument();
    PageContent pc = new PageContent();
    FixedPage fp = new FixedPage();
    TextBlock tb = new TextBlock();

    //add some text to a TextBox object
    tb.Text = "This is some test text";
    //add the text box to the FixedPage
    fp.Children.Add(tb);
    //add the FixedPage to the PageContent 
    pc.Child = fp;
    //add the PageContent to the FixedDocument
    fd.Pages.Add(pc);

    return fd;
}
票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15267621

复制
相关文章

相似问题

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