简体   繁体   English

有效的按钮不会打印

[英]Buttons with effect won't print

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. 这不是一个真正的关键问题,但如果有人有一个解决方法会很好。

The Effects like that are implemented as pixel shaders that run on the GPU. 像这样的效果实现为在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. 我最好的猜测是,在CPU上完成了对打印作业的渲染,因此无法访问必要的像素着色器来进行绘制。

Probably your best bet is to disable the drop shadows just before printing, then reenable them after. 可能你最好的选择是在打印前禁用阴影,然后重新启用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM