0
如何以編程方式關閉WPF PrintDialog
?我試圖通過反射來調用Finalize
,但這也沒有關閉它。以下是我試過:WPF:如何編程式關閉PrintDialog?
using System;
using System.Reflection;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
namespace WpfApplication15
{
partial class Window1 : Window
{
PrintDialog _printDialog;
public Window1()
{
InitializeComponent();
new Thread(OpenDialog).Start();
new Thread(CloseDialog).Start();
}
void OpenDialog()
{
Thread.Sleep(1000);
Dispatcher.BeginInvoke((Action)OpenDialogImpl);
}
void OpenDialogImpl()
{
_printDialog = new PrintDialog();
_printDialog.ShowDialog();
}
void CloseDialog()
{
Thread.Sleep(2000);
Dispatcher.BeginInvoke((Action)CloseDialogImpl);
}
void CloseDialogImpl()
{
var type = typeof(PrintDialog);
var flags = BindingFlags.Instance | BindingFlags.NonPublic;
var finalize = type.GetMethod("Finalize", flags);
finalize.Invoke(_printDialog, null);
MessageBox.Show("Finalized");
}
}
}
是否有原因,用戶無法手動關閉此對話框?也許你可以發佈一些背景信息給你的問題,這可能會有所幫助。謝謝! – Pwninstein 2010-02-18 17:47:43
我想實現自動註銷。 – 2010-02-18 18:46:33
我有類似的問題,並在這裏張貼答案; http://stackoverflow.com/questions/17282082/wpf-accessing-opened-print-dialog-and-close-them – 2013-06-24 19:01:31