C# 无法在WPF中打印

C# 无法在WPF中打印,c#,wpf,printdialog,C#,Wpf,Printdialog,我这里有这样一个问题。我在WPF项目中有一个窗口,还有一个按钮,上面有我想用打印机打印的内容。我对该按钮的点击事件如下 PrintDialog dlg = new PrintDialog(); Window currentMainWindow = Application.Current.MainWindow; Application.Current.MainWindow = this; if ((bool)dlg.ShowDialog().GetValueOrDefault()) {

我这里有这样一个问题。我在WPF项目中有一个窗口,还有一个按钮,上面有我想用打印机打印的内容。我对该按钮的点击事件如下

PrintDialog dlg = new PrintDialog();
Window currentMainWindow = Application.Current.MainWindow;
Application.Current.MainWindow = this;
if ((bool)dlg.ShowDialog().GetValueOrDefault())
{
     Application.Current.MainWindow = currentMainWindow; 
}
当我点击buton时,打印对话框弹出。 在这里 但是当点击打印时,什么也没有发生,对话框只是关闭,没有结果,它不工作,不使用Adobe PDF,不使用ARX CoSign

怎么办?谢谢你的辛勤劳动

    var printDoc = new PrintDocument()
    var dlg = new PrintDialog()

    If(dlg.ShowDialog() == DialogResult.OK)
    {
           printDoc.Document = [doc to print]
           printDoc.Setting = dlg.settings
           PrintDoc.print()
    }

在此处输入代码

PrintDialog dlg = new PrintDialog();
Window currentMainWindow = Application.Current.MainWindow;

        Application.Current.MainWindow = this;

        if ((bool)dlg.ShowDialog().GetValueOrDefault())
        {
            Application.Current.MainWindow = currentMainWindow; // do it early enough if the 'if' is entered
            dlg.PrintVisual(this, "Certificate");
        }

你必须创建一个新的“打印文档”或类似的东西,我在火车atm机上,我会在我关机时尝试完整回答,希望这有助于短期查看问题,看看答案是否有用。你到底想打印什么?@AdityaBokade我正在打印当前窗口。但什么是打印文档类?它使用什么组件?我不能用它。获取错误,因为它不理解什么是PrintDocument