如何阻止选择项目用户在列表框中没有禁用它 [英] How to stop user from selecting items in a listbox without disabling it

查看:100
本文介绍了如何阻止选择项目用户在列表框中没有禁用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也有一些是我需要做的,名单东西WPF,但我不希望用户单击列表,列表框中没有一个属性来禁用选择。您可以禁用控制,但是这不是我所需要的,因为它的样式和食堂,使文字难以阅读。我的意思是一样的东西:



<预类=郎XAML prettyprint-覆盖> <列表框IsEnabled ={结合的IsValid}。 ..> ...< /列表框>



我不知道是否有这样的:



<前类=郎XAML prettyprint-覆盖> <列表框选择=已禁用...> ...< /列表框>



或者,如果存在以挂牌不同的项目添加到列表框

$ B $替代b

现在的问题是,有没有办法可以列出WPF内容和用户不能选择那些项目?


解决方案

使用的的ItemsControl 的ListBox 的。 ItemsControl的是无外观控制



不过的不支持虚拟化技术(默认情况下)为ItemsControl的的,你必须做一些改变来支持虚拟化(的你想要的情况下< 。/ EM>)



如果你想在这里支持虚拟化,请参阅本 - 的虚拟化一个ItemsControl






要么你可以设置的 IsHitTestVisible 上的 ListBoxItem的的其中禁止对任何鼠标输入。你可以将它设置使用的 ItemContainerStyle



 <&ListBox中的GT; 
< ListBox.ItemContainerStyle>
<风格的TargetType =ListBoxItem的>
< setter属性=IsHitTestVisibleVALUE =FALSE/>
< /样式和GT;
< /ListBox.ItemContainerStyle>
< /列表框>


There is something i need to do, list something in WPF but i don't want the users to click on the list, the list box does not have a property to disable selection. You can disable the control, but that's not what i need, because it messes with the styles and makes the text difficult to read. I mean there is something like:

<ListBox IsEnabled="{Binding IsValid}" ...> ... </ListBox>

I wonder if there is something like:

<ListBox Selection="Disabled" ...> ... </ListBox>

Or if there exists an alternative to listing items different to a list box

The question is, is there a way to list content in WPF and that the users can't select those items??

解决方案

Use ItemsControl in place of ListBox. ItemsControl is a lookless control.

But virtualization is not supported (by default) for ItemsControl, you have to do some changes to support virtualization(in case you want).

Refer to this if you want to support virtualization here - Virtualizing an ItemsControl.


Either you can set IsHitTestVisible to false on ListBoxItem which disallows any mouse inputs on it. You can set it using ItemContainerStyle.

    <ListBox>
        <ListBox.ItemContainerStyle>
            <Style TargetType="ListBoxItem">
                <Setter Property="IsHitTestVisible" Value="False"/>
            </Style>
        </ListBox.ItemContainerStyle>
    </ListBox>

这篇关于如何阻止选择项目用户在列表框中没有禁用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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