1

我找到了打印 Wpf 网格内容的功能,但打印被裁剪。有人能知道为什么吗?

功能:

private void PrintTest()
        {
            FlowDocument document;
            Window window;
            CreateWindowToPrint(out document, out window);    
            PrintDialog printDialog = new PrintDialog();   
            window.Show();
            IDocumentPaginatorSource dps = document;
            if (printDialog.ShowDialog() == true)
            {
                printDialog.PrintDocument(dps.DocumentPaginator, "test");
            }
        }

和:

 private void CreateWindowToPrint(out FlowDocument document, out
 Window window)
         {
             document = new FlowDocument {  };
             var test = new PrintedTest() { DataContext = this.DataContext };
             document.Blocks.Add(new BlockUIContainer { Child = test });
             window = new Window {Content = document, Visibility =       System.Windows.Visibility.Hidden };
         }

UserControl PrintedTest 包含我的网格。

4

1 回答 1

1

我真的没有太多在 WPF 中打印的经验,但我想我会尝试一下。我可以重现您的问题,但到目前为止我无法解决。但在我的研究中,我找到了一种替代方法,它更简单地打印网格:

        var printDialog = new PrintDialog();
        var result = printDialog.ShowDialog();
        if (result.HasValue && result.Value)
        {
            var testControl = new PrintedTest() { DataContext = this.DataContext };
            printDialog.PrintVisual(testControl, "My WPF printing a DataGrid");
        }

而不是发送 PrintTest 您实际上可以直接发送网格。

于 2013-04-23T01:53:34.507 回答