2014-03-13 75 views
1

我一直在閱讀所有內容,但似乎找不到任何使用PrintVisual(...)打印窗口而不調用Show( ) 在上面。有沒有人可以提供幫助?如果即使說它不能發生,所以我可以尋找替代解決方案。是否有可能在未調用Show()的窗口上使用PrintVisual

此線程:Best method to print using wpf 4 似乎是很多人蔘考,但它仍然需要調用Show()。

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

回答

0

只是做

var printDialog = new PrintDialog(); 
printDialog.PrintVisual(wpfControl, "Sample Print"); 

這將打印到它被分配到默認打印機。如果要在不必調用Show方法的情況下對其進行擴展,則需要爲PrintDialog類設置PrintQueuePrintTicket

假設您有權訪問您的窗口並將其命名爲contentVisual

contentVisual.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); 
contentVisual.Arrange(new Rect(contentVisual.DesiredSize)); 
contentVisual.UpdateLayout(); 

然後調用Print

+0

我試過了,但沒有先調用wpfWindow.Show()的ActualHeight和ActualWidth的都是0.0這麼一個空白頁會打印。 –

+0

讓我看看你的控制。 –

+0

編輯的問題顯示窗口 –

相關問題