WPF:禁用列表框,但启用滚动 [英] WPF: Disable ListBox, but enable scrolling

查看:53
本文介绍了WPF:禁用列表框,但启用滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

整个早晨,我的头都撞到了.

Been banging my head against this all morning.

基本上,我有一个列表框,我想让人们在长时间运行的过程中不要更改选择,但允许他们仍然滚动.

Basically, I have a listbox, and I want to keep people from changing the selection during a long running process, but allow them to still scroll.

解决方案:

所有答案都很好,我接受了吞咽鼠标事件,因为那是最直接的方法.我将PreviewMouseDown和PreviewMouseUp连接到一个事件,该事件检查了我的backgroundWorker.IsBusy,以及是否将事件args上的IsHandled属性设置为true.

All the answers were good, I went with swallowing mouse events since that was the most straight forward. I wired PreviewMouseDown and PreviewMouseUp to a single event, which checked my backgroundWorker.IsBusy, and if it was set the IsHandled property on the event args to true.

推荐答案

诀窍是不真正禁用.禁用将锁定滚动框中的所有消息.

The trick is to not really disable. Disabling will lock out all messages from the scroll box.

在长时间操作期间,使用其.ForeColor属性将列表框中的文本显示为灰色,并吞下所有鼠标单击.这将模拟禁用控件并允许滚动不受阻碍.

During the long operation, gray out the text in the list box using its .ForeColor property and swallow all mouse clicks. This will simulate disabling the control and allow scrolling unimpeded.

这篇关于WPF:禁用列表框,但启用滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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