I am trying to print a WPF window with the following code:
PrintDialog printDialog = new PrintDialog(); if (printDialog.ShowDialog() == true) { var printArea = printDialog.PrintQueue.GetPrintCapabilities() .PageImageableArea; var item = (FrameworkElement)this; DrawingVisual visual = new DrawingVisual(); using (DrawingContext context = visual.RenderOpen()) { VisualBrush brush = new VisualBrush(item); context.DrawRectangle(brush, null, new Rect(new Point(printArea.OriginWidth, printArea.OriginHeight), new Size(item.ActualWidth, item.ActualHeight))); } printDialog.PrintVisual(visual, String.Empty); }
This works very well, but for some strange reason, the buttons do not appear in the printed document.
I found that the reason is that I set DropShadowEffect to the button, if I remove it, the button will appear in the printed document:
<Setter Property="Effect"> <Setter.Value> <DropShadowEffect Color="Gray" Opacity=".50" ShadowDepth="8" /> </Setter.Value> </Setter>
This is not a very important issue, but it would be nice if someone had a workaround.
c # wpf
Julien n
source share