在WPF中,要将FixedPage添加到代码中的FixedDocument中,需要:
var page = new FixedPage();
var pageContent = new PageContent();
((IAddChild)pageContent).AddChild(page);然而,这似乎是唯一的办法:
PageContent中,必须强制转换到显式接口实现是很难看的。PageContent的基本操作并不简单。这些文档实际上并没有解释如何做到这一点,我也找不到任何其他关于如何做到这一点的信息。还有别的办法吗?正确的方式?
发布于 2013-04-09 19:16:23
根据MSDN文档,只需将一个FixedPage对象添加到PageContent.Child属性中,然后通过调用FixedDocument.Pages.Add方法将其添加到FixedDocument中。
例如:
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;
}https://stackoverflow.com/questions/15267621
复制相似问题