如何在 ListBox 中禁用 ScrollViewer? [英] How to disable ScrollViewer in ListBox?

查看:21
本文介绍了如何在 ListBox 中禁用 ScrollViewer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表框.它具有内部 ScrollViewer,因此我可以使用鼠标滚轮滚动 ListBox 内容.它工作正常,直到我设置包含另一个列表框的项目模板(实际上,我有 4 个嵌套的列表框 =)).问题是内部 ListBox 的 ScrollViewer 窃取了轮转事件.有什么简单的方法可以防止这种行为吗?

I have a ListBox. It has internal ScrollViewer, so I can scroll ListBox content with mouse wheel. It works fine until I set item template that contains another ListBox (in fact, I have 4 nested ListBoxes =)). Problem is that internal ListBox's ScrollViewer steals wheeling event. Is there any easy way to prevent this behavior?

我有像这样的带有 ItemContainerStyle 的 ListBox:

I had ListBox with ItemContainerStyle like this:

<Style x:Key="ListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
    <Setter Property="BorderBrush" Value="Black"/>
     ... 
</Style>
<ListBox ItemContainerStyle="{StaticResource ListBoxItemStyle}" />

如何在这样的资源中为 ItemContainer 的项目边框设置样式?据我所知,ContentPresenter 是 ItemsControl 的项目容器.但它没有边框,所以我无法设计它.

How can I set style for ItemContainer's item border in resources like this? As I know ContentPresenter is item container of ItemsControl. But it hasn't Border, so I can't style it.

推荐答案

您可以将 ScrollViewerListBox 中删除,方法是将其控件模板更改为更简单的内容:

You can remove the ScrollViewer from a ListBox by changing its control template to something much simpler:

<ListBox>
    <ListBox.Template>
        <ControlTemplate>
            <ItemsPresenter />
        </ControlTemplate>
    </ListBox.Template>
    ...
</ListBox>

然而,我质疑嵌套 ListBoxes 的价值.请记住,每个 ListBox 都是一个选择器,并且具有选择"哪个项目的概念.在选定的项目中,在选定的项目中拥有选定的项目真的有意义吗?

However, I question the value of nesting ListBoxes. Remember that each ListBox is a Selector and has a concept of which item is "selected". Does it really make sense to have a selected item inside a selected item, inside a selected item?

我建议将内部"ListBoxes 更改为简单的 ItemsControls,以便嵌套列表不能包含选定的项目.这将使用户体验更加简单.您可能仍然需要以相同的方式重新模板内部 ItemsControls 以删除滚动条,但至少用户不会对选择"哪个项目感到困惑.

I would suggest changing the "inner" ListBoxes to simple ItemsControls so that the nested lists can't have selected items. That would make for a much simpler user experience. You may still need to retemplate the inner ItemsControls in the same way to remove the scrollbars, but at least the user won't get confused about which item is "selected".

这篇关于如何在 ListBox 中禁用 ScrollViewer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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