What is the correct way to add PageContent / FixedPage to FixedDocument in WPF?

In WPF, to add code FixedPageto FixedDocument, you must:

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

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

This, however, is the only way:

  • The MSDN documentation explicitly says that this should not be done ("This API supports the .NET Framework and is not intended to be used directly from your code." PageContent.IAddChild.AddChild Method ).

  • Incorrectly applying to an explicit interface implementation to add content to PageContent.

  • Do not just do the basic operation PageContent.

The documentation does not really explain how to do this, and I could not find any other information on how to do this. Is there another way? "The right way?

+5
1

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;
}
+7

All Articles