WPF访问打开的打印对话框并关闭它们

WPF访问打开的打印对话框并关闭它们

问题描述:

我有一个WPF应用程序,该应用程序在闲置5分钟后需要注销用户.

I have a WPF application, which needs to log out user after 5 min of inactivity.

但是,如果用户打开任何页面的打印对话框,并且在5分钟内未触摸屏幕, 即使我注销用户并清除所有子元素,打印对话框仍然停留在WPF表单的顶部,并且有人可以继续打印页面用户留下的内容.

But if user open a print dialog of any page, and do not touch screen for 5 minutes, even if I log out user and clear all child elements, print dialog still stays on top of WPF form and somebody can come and continue to print what ever page user stayed.

我尝试使用;

Window window = Application.Current.MainWindow;

FocusManager.GetFocusedElement();

但无法访问并关闭PrintDialog.

but could not achieve to access to PrintDialog and close it.

如果用户未响应打印对话框,有什么方法可以访问并关闭它?

Is there any way to access it and close if user did not respond to print dialog?

我通过使用

白色项目. http://white.codeplex.com/wikipage ?title =工作%20with%20window& referringTitle =使用%20white编程%20

通过使用应用程序类,我能够访问WPF项目中的所有ModalDialogs,并将其关闭.

By using application class, I am able to access all ModalDialogs in WPF project, and close them.

  Application application = White.Core.Application.Attach(Process.GetCurrentProcess().Id);

private void dispatcherTimer_Tick(object sender, EventArgs e)
    {
        White.Core.UIItems.WindowItems.Window window = application.GetWindow("MainWindow");
        List<White.Core.UIItems.WindowItems.Window> modalWindows = window.ModalWindows();
        foreach (White.Core.UIItems.WindowItems.Window modalWindow in modalWindows)
        {
            modalWindow.Close();
        }
    }