[英]How can I use a WPF FlowDocument or FixedDocument to compose a printable page from on screen controls?
[英]WPF - How do I remove page from FixedDocument?
我有一個名為“ 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;
}
}
現在,我可以創建一個FixedDocument並添加3個頁面,其內容分別對應於該順序的“ Page1”,“ Page2”和“ Page3”:
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);
}
現在有一種方法可以從FixedDocument刪除頁面嗎? 我知道我可以使用document.Pages[2].Child.Children.Clear();
清除特定頁面的內容document.Pages[2].Child.Children.Clear();
例如,但是如何刪除頁面本身?
根據文檔 ,FixedDocument應該是一種顯示/打印機制,並且不是交互式/可編輯的。
話雖如此,您可以通過允許對MyPage類中的Text進行更改,然后在更改后根據需要重新構建FixedDocument,來實現基本的編輯。
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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.