简体   繁体   English

如何在 C# WPF 中禁用鼠标按钮?

[英]How to disable mouse buttons in C# WPF?

During big files loading I want to disable mouse buttons to unable user to click on UI elements and triggers events.在大文件加载期间,我想禁用鼠标按钮以使用户无法单击 UI 元素并触发事件。

Edit When I am loading big size file in my WPF Caliburn Micro application I changed IsEnabled property of Listbox to false, because I want to disable a button during this process.编辑当我在 WPF Caliburn Micro 应用程序中加载大尺寸文件时,我将 Listbox 的 IsEnabled 属性更改为 false,因为我想在此过程中禁用按钮。 Next when file is loaded I changed IsEnabled property of Listbox to true.接下来加载文件时,我将 Listbox 的 IsEnabled 属性更改为 true。 After that every click on disabled button raised events and I did not want that.之后,每次点击禁用按钮都会引发事件,我不希望这样。 I don't know how to remove this events, and where there are stored, so i thought that the easier way to solve this problem is to disable mouse buttons during file loading process.我不知道如何删除这个事件,以及存储在哪里,所以我认为解决这个问题的更简单方法是在文件加载过程中禁用鼠标按钮。 But it is also not easy... Thank You in advance!但这也不容易......提前谢谢你!

If you only want to disable mouse buttons, the user can still use the keyboard.如果您只想禁用鼠标按钮,用户仍然可以使用键盘。 So you need a different technique.所以你需要一种不同的技术。 You can add a hidden Gird with Opacity="0.5" to your window.您可以将Opacity="0.5"的隐藏网格添加到 window。 When you want to prevent the user from using the window, just call visible the grid.当您想阻止用户使用 window 时,只需调用可见网格。

What about overriding SelectionChanged event on ListBox and setting it to Handled = true when loading big data?在加载大数据时覆盖 ListBox 上的SelectionChanged事件并将其设置为Handled = true怎么样?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM