Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在一个打印作业中组合多个PrintVisual()?_C#_Wpf_Printing - Fatal编程技术网

C# 如何在一个打印作业中组合多个PrintVisual()?

C# 如何在一个打印作业中组合多个PrintVisual()?,c#,wpf,printing,C#,Wpf,Printing,我有一个C#WPF应用程序(.NET 4.6),需要打印许多页面对象。 每个页面在XAML编辑器中设置为正好1页A4大小,内容由放置在页面上的许多标签、边框和图像组件生成。 我向我的Page类添加了一个方法,该方法在运行时向页面添加一些动态数据,然后使用PrintVisual() 事实上:它是一个循环,用动态内容填充页面对象,然后调用PrintVisual()来打印它。对于每个迭代,页面中都会放置一些新内容。(请参见示例代码。) //页面对象的打印方法。 public void PrintIt(

我有一个C#WPF应用程序(.NET 4.6),需要打印许多页面对象。
每个页面在XAML编辑器中设置为正好1页A4大小,内容由放置在页面上的许多标签、边框和图像组件生成。
我向我的Page类添加了一个方法,该方法在运行时向页面添加一些动态数据,然后使用
PrintVisual()

事实上:它是一个循环,用动态内容填充页面对象,然后调用
PrintVisual()
来打印它。对于每个迭代,页面中都会放置一些新内容。(请参见示例代码。)

//页面对象的打印方法。
public void PrintIt(整版总页数)
{
PrintDialog pDialog=新建PrintDialog();
//如果未取消,则打印
if(pDialog.ShowDialog()==false)返回;//用户已取消。不用麻烦了

对于(int pagenum=1;I have you read?@BugFinder我看到了,但我不太明白这对我有什么帮助。在anser的第二个视图中……我是否正确地假设了其中的“fixedPage.Children.Add((UIElement)visual);”我可以替换为“visual”用我自己的页面对象?我希望too@BugFinder这不起作用。我需要一个UIElement,并且没有从页面到UIElement的任何直接转换。@AndreLuus没有。不幸的是没有。因为页面数>1的情况很少见,我们只是学会了适应它。
// Print method of the Page object.
public void PrintIt(int totalpages)
{
     PrintDialog pDialog = new PrintDialog();
     // If not cancelled then print 
     if (pDialog.ShowDialog() == false) return;  // User cancelled. Don't bother
     for(int pagenum=1; i<=totalpages; i++)
     {
         // Omitted several dozen statements that fill/update the content of various 
         // label components based on the pagenumber.
         this.UpdateLayout();     // Required to re-render new page properly before printing.
         pDialog.PrintVisual(this, "My PrintJob");
     }
}