Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Buttons with effect won't print

Tags:

c#

wpf

I'm 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);
}

It works really well, but for a really strange reason, the buttons doesn't appear on the printed document.

I discovered that the cause seem to be that I have set a DropShadowEffect on the button, if I remove it, the button appears on the printed document :

<Setter Property="Effect">
    <Setter.Value>
        <DropShadowEffect Color="Gray" Opacity=".50" ShadowDepth="8" />
    </Setter.Value>
</Setter>

This is not really a critical issue, but it would be nice if someone had a workaround.

like image 719
Julien N Avatar asked Sep 04 '13 16:09

Julien N


1 Answers

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

Probably your best bet is to disable the drop shadows just before printing, then reenable them after.

like image 169
moron4hire Avatar answered Oct 20 '22 00:10

moron4hire