嵌套列表框中的鼠标滚轮
我目前正在使用 MVVM 使用 C# 开发 WPF 项目。在此项目中,我有一个列表框,用于为项目源中的每行数据加载用户控件。
为我的集合中的每个项目添加的用户控件还包含一个从数据库填充的列表框。第二个列表框经常会增长,因此使每个项目都比第一个列表框的视图更大。
我的问题是,如何使我的列表框平滑滚动。现在,它从一个项目的顶部跳到下一个项目的顶部。由于每个项目都比列表框的视图大,因此我需要能够滚动而无需从每个项目的顶部跳到下一个项目。
我已经使用滚动视图来实现此目的,但列表框随后拦截鼠标滚轮事件,并且不允许我在不将鼠标悬停在滚动条上的情况下进行滚动。
有更好的方法吗?
更新:
我可以使用滚动视图控件实现平滑滚动,但当鼠标位于滚动视图内时无法滚动。我必须将鼠标悬停在滚动条上才能滚动。
就像有什么东西正在拦截我的鼠标滚轮事件。
I am currently working on a WPF project in C# using MVVM. In this project I have a list box that loads a user control for each row of data in my items source.
The user control that gets added for each item in my collection also contains a list box that is filled from a database. This second list box often grows and therefore makes each item larger than the view of the first listbox.
My question is, how to I make my listbox have smooth scrolling. Right now it jumps from the top of one item the the top of the next. Since each item is bigger than the view of the listbox I need to be able to scroll without jumping from the top of each item to the next.
I have used a scrollview to achieve this but the list box then intercepts the mouse wheel event and will not allow me to scroll without hovering over the scroll bar.
Is there a better way to do this?
UPDATE:
I can get smooth scrolling using the scrollview control but I cannot scroll while my mouse is inside the scrollview. I have to have my mouse over the scrollbar in order to scroll.
It is like something is intercepting my mousewheel event.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我能够通过使用 ItemsControl 而不是 ListBox 来实现我想要做的事情。它就像 ListBox 控件一样加载,并将所有数据拉入其中,并让 ScrollView 处理滚动。它没有像列表框那样拦截鼠标滚轮。
如果您不需要能够选择某个项目,我强烈建议使用 ItemsControl。
I was able to achieve what I was trying to do by using a ItemsControl rather than the ListBox. It loaded just like the ListBox control and pulled all of my data into it and let the ScrollView handle the scrolling. It did not intercept the mousewheel even like the listbox did.
If you do not need to be able to select an item, I highly recommend using the ItemsControl.
您可以在列表框中设置以下属性
ScrollViewer.CanContentScroll="False"
。You can set on the Listbox the following Property
ScrollViewer.CanContentScroll="False"
.