This is a migrated thread and some comments may be shown as answers.

Element is already a child of another element in PrintDocument

0 Answers 45 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Roger
Top achievements
Rank 1
Roger asked on 12 Apr 2012, 02:53 PM
I have created a UIElement in which my layout for "Reports - Receipt - Print".
The layout contains  Binding and other controls.

When I Click the Button for print
It throws an exception "Element is already the child of another element.".
In this line ----> canvas.Children.Add(this.DRReceipt);
<StackPanel x:Name="DRReceipt">
 
...RadGriView with binding...
...Label...
...Images...
 
</StackPanel>

var doc = new PrintDocument();
 
var offsetY = 0d;
var totalHeight = 0d;
 
Canvas canvas = new Canvas();
canvas.Children.Add(this.DRReceipt);
 
doc.PrintPage += (s, d) =>
{
    d.PageVisual = canvas;
    if (totalHeight == 0)
    {
        totalHeight = canvas.DesiredSize.Height;
    }
    Canvas.SetTop(canvas, -offsetY);
    offsetY += d.PrintableArea.Height;
    d.HasMorePages = offsetY <= totalHeight;
};
doc.Print("DeliveryReceipt");

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Roger
Top achievements
Rank 1
Share this question
or