[翻译]  Buttons with effect won't print

[CHINESE]  带效果的按钮不会打印


I'm trying to print a WPF window with the following code :

我正在尝试使用以下代码打印WPF窗口:

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 :

我发现原因似乎是我在按钮上设置了DropShadowEffect,如果我将其删除,则按钮会出现在打印文档上:

<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.

这不是一个真正的关键问题,但如果有人有一个解决方法会很好。

1 个解决方案

#1


2  

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.

像这样的效果实现为在GPU上运行的像素着色器。我最好的猜测是,在CPU上完成了对打印作业的渲染,因此无法访问必要的像素着色器来进行绘制。

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

可能你最好的选择是在打印前禁用阴影,然后重新启用它们。


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
© 2014-2018 ITdaan.com 粤ICP备14056181号