0
視覺v
是我嘗試打印的用戶控件中的網格部分的一部分。我是新來的C#,並不完全確定爲什麼我得到這個錯誤。這可能與xaml代碼有關嗎?指定的元素已經是另一個元素的邏輯子元素。首先斷開它從用戶控件打印多個頁面
private void Print(Visual v)
{
var pd = new PrintDialog();
var document = new FixedDocument();
var fixedPage = new FixedPage();
//System.Windows.FrameworkElement e = v as System.Windows.FrameworkElement;
//if(e == null)
Transform originalScale = fixedPage.LayoutTransform;
//get selected printer capabilities
System.Printing.PrintCapabilities capabilities = pd.PrintQueue.GetPrintCapabilities(pd.PrintTicket);
System.Windows.Size sz = new System.Windows.Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
fixedPage.Width = sz.Width;
fixedPage.Height = sz.Height;
// Add visual, measure/arrange page.
fixedPage.Children.Add((FrameworkElement)v);
fixedPage.Measure(sz);
fixedPage.LayoutTransform = new ScaleTransform(0.2823293807641634 + 0.2498215560314061, 0.2823293807641634 + 0.2498215560314061);
fixedPage.Arrange(new System.Windows.Rect(new System.Windows.Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));
fixedPage.UpdateLayout();
fixedPage.LayoutTransform = originalScale;
//var pageContent = new PageContent();
//((IAddChild)pageContent).AddChild(internalPage);
//document.Pages.Add(pageContent);
pd.PrintDocument(document.DocumentPaginator, "My Document");
}
當我嘗試打印控件時,在xaml代碼中我有 usercontrol>它給了我同樣的錯誤。 –
user2708073
您正好將它添加到xaml中的可視化樹中,然後再噴射另一個可視化樹以在fixedPage.Children.Add((FrameworkElement)v)打印;你根本無法做到這一點。 – Rafal