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

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

问题描述

我有一个ListBox.它具有内部ScrollViewer,因此我可以使用鼠标滚轮滚动ListBox内容.在我设置包含另一个ListBox的项目模板之前,它可以正常工作(实际上,我有4个嵌套的ListBoxes =).问题是内部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.

推荐答案

您可以通过将ScrollViewer的控制模板更改为更简单的方法来将其从ListBox中删除:

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天全站免登陆