C# 是否可以在未调用Show()的窗口上使用PrintVisual
我一直在阅读,但我似乎找不到任何使用PrintVisual打印窗口的示例。。。不打电话给Show。有人可以帮忙吗?如果我甚至说这不可能发生,那么我可以寻找替代的解决方案 此线程: 似乎是很多人提到的,但它仍然需要一个电话来显示C# 是否可以在未调用Show()的窗口上使用PrintVisual,c#,wpf,printing,C#,Wpf,Printing,我一直在阅读,但我似乎找不到任何使用PrintVisual打印窗口的示例。。。不打电话给Show。有人可以帮忙吗?如果我甚至说这不可能发生,那么我可以寻找替代的解决方案 此线程: 似乎是很多人提到的,但它仍然需要一个电话来显示 <Window x:Class="Paymax.Printing.PrintPayAdvice" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
<Window x:Class="Paymax.Printing.PrintPayAdvice"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<DockPanel>
<StackPanel>
<TextBlock Text="Testing 123" />
</StackPanel>
</DockPanel>
</Window>
照办
var printDialog = new PrintDialog();
printDialog.PrintVisual(wpfControl, "Sample Print");
它将打印到指定给它的默认打印机。如果要在不调用Show方法的情况下扩展PrintDialog类,则需要为其设置PrintQueue和PrintTicket
假设您有权访问您的窗口并将其命名为contentVisual
然后调用Print我试过了,但没有先调用wpfWindow.Show,实际高度和实际宽度都是0.0,所以会打印一个空白页。给我看看你的控件。试过了,但是contentVisual.DesiredSize={0,0}所以仍然没有显示任何内容。你真的不想调用Show吗?你能做一场表演,但是能见度被压缩了吗?
contentVisual.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
contentVisual.Arrange(new Rect(contentVisual.DesiredSize));
contentVisual.UpdateLayout();