简体   繁体   中英

WPF - How do I remove page from FixedDocument?

I have a simple class called "MyPage":

public class MyPage
{
    public TextBlock tbParagraph;
    public FixedPage page;
    public PageContent content;

    public MyPage(string Text)
    {
        tbParagraph = new TextBlock();
        page = new FixedPage();
        content = new PageContent();

        tbParagraph.Text = Text;
        page.Children.Add(tbParagraph);
        content.Child = page;
    }
}

Now I can create a FixedDocument and add 3 pages with the content of "Page1", "Page2" and "Page3" respective to the order:

FixedDocument document = new FixedDocument();
public List<MyPage> listPages = new List<MyPage>();
listPages.Add(new MyPage("Page 1"));
listPages.Add(new MyPage("Page 2"));
listPages.Add(new MyPage("Page 3"));

foreach(MyPage pg in listPages)
{
    document.Pages.Add(pg.content);
}

Now is there a way to remove pages from FixedDocument? I know I can clear the specific page content with document.Pages[2].Child.Children.Clear(); for example, but how do I remove a Page itself?

From the documentation , FixedDocument is meant to be a display/print mechanism, and is not an interactive/editable.

That being said, you could achieve basic editing by allowing changes to the Text in your MyPage class and then re-building the FixedDocument as needed after the changes.

public class MyPage
{
    public TextBlock tbParagraph;
    public FixedPage page;
    public PageContent content;
    public string Text {get; set;}

    public MyPage(string myText)
    {
       Text = myText;
    }

    public PageContent GetPage()
    {
        tbParagraph = new TextBlock();
        page = new FixedPage();
        content = new PageContent();

        tbParagraph.Text = Text;
        page.Children.Add(tbParagraph);
        content.Child = page;
        return content;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM