Is it possible to use PrintVisual on a window that hasn't called Show()
I've been reading all over but I cannot seem to find any examples of printing a window using PrintVisual(...) without calling Show() on it. Is there anyone who can assist? If even to say that it cannot happen so I can look for alternative solution.
This thread: Best method to print using wpf 4 seems to be what a lot of people reference, but it still requires a call to 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>
var printDialog = new PrintDialog(); printDialog.PrintVisual(wpfControl, "Sample Print");
It would print to default printer that it is assigned to. You want to setup the PrintQueue and PrintTicket for the PrintDialog class if you want to extend it without having to call the Show method.
Assuming you have access to your window and named it contentVisual.
contentVisual.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); contentVisual.Arrange(new Rect(contentVisual.DesiredSize)); contentVisual.UpdateLayout();
Then call Print