Buttons with effect will not print

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.

+7
c # wpf
source share
1 answer

Effects like this are implemented as pixel shaders that run on the GPU. My best guess is that the rendering done for the print job is done on the CPU, so it will not have access to the necessary pixel shaders for drawing.

It is probably best to turn off the shadows for printing immediately before printing, and then repeat them after.

+2
source share

All Articles