WPF访问打开的打印对话框并关闭它们 [英] WPF accessing opened print dialog and close them

查看:97
本文介绍了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();
        }
    }

这篇关于WPF访问打开的打印对话框并关闭它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆