gpt4 book ai didi

.net - 没有 ListBox.SelectionMode ="None",是否有另一种方法可以禁用列表框中的选择?

转载 作者:行者123 更新时间:2023-12-03 04:14:02 25 4
gpt4 key购买 nike

如何禁用列表框中的选择?

最佳答案

方法 1 - ItemsControl

除非您需要 ListBox 的其他方面,否则可以使用 ItemsControl 来代替。它将项目放置在 ItemsPanel 中,并且没有选择的概念。

<ItemsControl ItemsSource="{Binding MyItems}" />

默认情况下,ItemsControl 不支持其子元素的虚拟化。如果您有很多项目,虚拟化可以减少内存使用并提高性能,在这种情况下,您可以使用方法 2 并设置 ListBox 的样式,或 add virtualisation to your ItemsControl .

方法 2 - 样式 ListBox

或者,只需设置 ListBox 的样式,使所选内容不可见。

<ListBox.Resources>
<Style TargetType="ListBoxItem">
<Style.Resources>
<!-- SelectedItem with focus -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Transparent" />
<!-- SelectedItem without focus -->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="Transparent" />
<!-- SelectedItem text foreground -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}"
Color="Black" />
</Style.Resources>
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
</Style>
</ListBox.Resources>

关于.net - 没有 ListBox.SelectionMode ="None",是否有另一种方法可以禁用列表框中的选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1398559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com