加引用:
using System.Windows.Printing;
xaml文件里:
//定义图片和文本打印变量
PrintDocument printImage;
public BeginControlChart 方法里:
//图片打印对象
printImage = new PrintDocument();
//图片打印事件处理
printImage.PrintPage += new EventHandler<PrintPageEventArgs>(printImage_PrintPage);
/// <summary>
/// 打印
/// </summary>
private void btnPrint_Click(object sender, RoutedEventArgs e)
{
//启动打印图片,出现打印对话框
printImage.Print(sTNameClick);
}
//确认打印后开始打印
private void printImage_PrintPage(object sender, PrintPageEventArgs e)
{
//确认打印,打印对象
e.PageVisual = this.gridVisifire;
}