Hi
You can use the code below to print the visual in WPF.
XAML Code:
<StackPanel Name="panel">
<Line x:Name="line1"
X1="280"
X2="280"
Y2="0"
Y1="300"
Stroke="Red" StrokeThickness="3" Fill="Red" />
<Button Content="Print" Click="OnPrint" Width="120" Height="30" />
</StackPanel>
In the code behind:
System.Windows.Controls.PrintDialog Printdlg = new System.Windows.Controls.PrintDialog();
privatevoid OnPrint(object sender, RoutedEventArgs e)
{
if ((bool)Printdlg.ShowDialog().GetValueOrDefault())
{
Size pageSize = newSize(Printdlg.PrintableAreaWidth, Printdlg.PrintableAreaHeight);
// sizing of the element.
panel.Measure(pageSize);
panel.Arrange(newRect(5, 5, pageSize.Width, pageSize.Height));
Printdlg.PrintVisual(panel, "Print line");
}
}
For a more versatile print example, you can refer this link, which includes the print preview:
http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/00bda5bf-a366-4dbe-8613-22edb7dfb449
Hope this helps.
Thanks.
Jim Zhou -MSFT