System.InvalidOperationException:特定元素已经是另一个元素的逻辑子元素。先断开连接

时间:2013-05-06 19:35:50

标签: c# wpf process writablebitmap

我正在尝试使用Flow Document打印一些段落和图像,如下面的代码所示

Paragraph invoiceID = new Paragraph(new Run("Invoice No : "+ txtInvoiceID.Text));
Paragraph qty001 = new Paragraph(new Run("Quantity : " + qtyText.Text));
Paragraph date001 = new Paragraph(new Run("Date : " +txtInvoiceDate.Text));

Section sec = new Section();
sec.Blocks.Add(invoiceID);
sec.Blocks.Add(qty001);
sec.Blocks.Add(date001);

FlowDocument fd = new FlowDocument();
PrintDialog pd = new PrintDialog();

fd.PageHeight = pd.PrintableAreaHeight;
fd.PageWidth = pd.PrintableAreaWidth;
fd.PagePadding = new Thickness(50);
fd.ColumnWidth = pd.PrintableAreaWidth;
fd.Blocks.Add(sec);
fd.Blocks.Add(new BlockUIContainer(barCodeImage));

IDocumentPaginatorSource dps = fd;
pd.PrintDocument(dps.DocumentPaginator,"Desciption");

我知道图像被进程锁定但我如何解锁此图像?

请帮助

由于

Jazaib

1 个答案:

答案 0 :(得分:-1)

在WPF中,每个控件只能有一个父级,因为你已经在xaml中定义了barCodeImage,它是某个容器的子级。 所以你可以从容器中删除它或克隆图像