本文介绍了wpf fixeddocument动态数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建FixedDocument
并向其中动态添加页面.
I am creating FixedDocument
and adding pages to it dynamically.
public partial class Window1 : Window
{
FixedDocument fd = new FixedDocument();
TextBlock page1Text = new TextBlock();
public Window1()
{
InitializeComponent();
}
private void Print_Click(object sender, RoutedEventArgs e)
{
PrintDialog pd = new PrintDialog();
fd.DocumentPaginator.PageSize = new Size(pd.PrintableAreaWidth, pd.PrintableAreaHeight);
for (int i = 0; i <= 5; i++)
{
FixedPage page1 = new FixedPage();
page1.Width = fd.DocumentPaginator.PageSize.Width;
page1.Height = fd.DocumentPaginator.PageSize.Height;
pages();
page1.Children.Add(page1Text);
PageContent page1Content = new PageContent();
((IAddChild)page1Content).AddChild(page1);
fd.Pages.Add(page1Content);
}
DocumentViewer dr = new DocumentViewer();
dr.Height = 700;
dr.Document =fd;
stack.Children.Add(dr);
}
private void pages()
{
page1Text.Text = "This is a test";
page1Text.FontSize = 40;
page1Text.Margin = new Thickness(96);
}
}
代码仍然错误提示page1content是另一个父级的子级.
The code is still giving error that page1content is a child of another parent.
推荐答案
我做到了.解决方法如下
I did it. The solution is as follows
private void Print_Click(object sender, RoutedEventArgs e)
{
PrintDialog pd = new PrintDialog();
fd.DocumentPaginator.PageSize = new Size(pd.PrintableAreaWidth,fd.PrintableAreaHeight);
for (int i = 0; i <= 5; i++)
{
FixedPage page1 = new FixedPage();
page1.Width = fd.DocumentPaginator.PageSize.Width;
page1.Height = fd.DocumentPaginator.PageSize.Height;
UIElement page1Text = pages();
page1.Children.Add(page1Text);
PageContent page1Content = new PageContent();
((IAddChild)page1Content).AddChild(page1);
fd.Pages.Add(page1Content);
}
DocumentViewer dr = new DocumentViewer();
dr.Height = 700;
dr.Document =fd;
stack.Children.Add(dr);
}
private UIElement pages()
{
Canvas pcan = new Canvas();
TextBlock page1Text = new TextBlock();
page1Text.Text = "This is a test";
page1Text.FontSize = 40;
page1Text.Margin = new Thickness(96);
pcan.Children.Add(page1Text);
return pcan;
}
您可以跳过画布.这是我的项目的要求,所以我正在尝试.
You can skip the canvas. It is requirment of my project so I was trying it.
这篇关于wpf fixeddocument动态数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!