视觉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");
}