10

在 WPF 中,为了将 a 添加FixedPageFixedDocument代码中,需要:

var page = new FixedPage();
var pageContent = new PageContent();

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

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

  • MSDN 文档明确指出不应该这样做('此 API 支持 .NET Framework 基础结构,不打算直接从您的代码中使用。'- PageContent.IAddChild.AddChild 方法)。

  • 为了将内容添加到PageContent.

  • 进行基本的操作并不简单PageContent

该文档实际上并未解释如何执行此操作,而且我找不到有关如何执行此操作的任何其他信息。还有其他方法吗?一个“正确”的方式?

4

1 回答 1

12

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

例如:

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;
}
于 2013-04-09T19:16:23.987 回答