简体   繁体   English

在长时间运行过程中禁用鼠标点击?

[英]Disable mouse clicks during long-running process?

I have an issue where when a button is clicked and the process takes a while, the user clicks on other locations on the GUI screen. 我有一个问题,当点击一个按钮并且该过程需要一段时间时,用户点击GUI屏幕上的其他位置。 Those button clicks get queued up in the dispatcher so after the initial button click those other locations get clicked. 这些按钮点击在调度程序中排队,因此在初始按钮单击后,单击其他位置。 I want to prevent this from happening so other UI controls don't get clicked after it's done processing. 我希望防止这种情况发生,因此其他UI控件在完成处理后不会被点击。

The only solution I can think of is to p/invoke into the mouse events and prevent them from being passed to the application while the button click is being processed. 我能想到的唯一解决方案是在处理按钮点击时调用鼠标事件并阻止它们传递给应用程序。 Is this the best approach? 这是最好的方法吗?

One of the easier solutions to this is to have some sort of semi-transparent overlay (potentially with progress information) that you pop up when there are long-running tasks going on. 对此更简单的解决方案之一是在有长时间运行的任务时弹出一些半透明覆盖(可能包含进度信息)。 That will reliably disable the entire UI until you remove the overlay (which keeps you from having to do a lot of changing/binding IsEnabled properties). 这将可靠地禁用整个UI,直到您删除覆盖(这使您不必进行大量更改/绑定IsEnabled属性)。

If the process takes a while, it is generally recommended to perform such process in a worker thread, rather than in a GUI thread. 如果该过程需要一段时间,通常建议在工作线程中而不是在GUI线程中执行此类过程。 So use BackgroundWorker approach like in this CodeProject article , and then use CanExecute method of commands associated with specified buttons, like here: 因此,在此CodeProject文章中使用BackgroundWorker方法,然后使用与指定按钮关联的命令的CanExecute方法,如下所示:

WPF Commanding – When do Commands re-evaluate their CanExecute method? WPF命令 - 何时命令重新评估其CanExecute方法?
WPF – CanExecute refreshed WPF - CanExecute刷新

EDIT: 编辑:

You can bind IsEnabled property of your other controls to the result of Command's CanExecute method. 您可以将其他控件的IsEnabled属性绑定到Command的CanExecute方法的结果。

How to disable combobox when command canExecute returns false 如何在命令canExecute返回false时禁用组合框
How to bind a ComboBoxItem's IsEnabled property to the result of a Command's CanExecute method 如何将ComboBoxItem的IsEnabled属性绑定到Command的CanExecute方法的结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在长时间运行的过程中,使用ReactiveUI,Observables,SubscribeOn和ObserveOn在UI中显示输出日志 - Using ReactiveUI, Observables, SubscribeOn, and ObserveOn to display an output log in UI during a long-running process 显示长时间运行过程的进度 - Show progress on long-running process 在长时间运行的任务中显示自定义对话框窗口 - Displaying a custom dialog window during a long-running task WinForm 应用程序 UI 在长时间运行期间挂起 - WinForm Application UI Hangs during Long-Running Operation 在Winforms中显示模式加载窗口以长时间运行 - Show modal loading window in Winforms for long-running process 返回之前,先使用DBContext Access启动长时间运行的进程 - Start Long-Running Process With DBContext Access Before Returning IIS进程之外的长期运行的存储过程 - Long-running stored procedure out of IIS process 关闭Windows服务中的长时间运行的进程 - Shutting down a Long-running process in a Windows Service 在长时间运行的过程中禁用Windows Update - Disable Windows Update during long running processes 使用 ReSharper,如何在长时间运行的单元测试期间显示调试输出? - Using ReSharper, how to show debug output during a long-running unit test?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM