我有一个带有AlternationCount=2的WPF列表框。
我想禁用对框中项目的选择,但我想保留颜色。
当我设置为IsEnabled="False"时,列表框中的项目选择被禁用,但文本和背景变为灰色。
如何在禁用选定内容的同时保持前景色和交替背景色为启用状态?
发布于 2017-10-27 01:09:35
ListBoxItem中有两个属性可能会有所帮助:Focusable和IsHitTestVisible。将其中一个设置为false,以禁用视图中的选择。(使用Focusable="false"时,ListBoxItems将在鼠标悬停时更改颜色)。设置IsEnabled="false"也会阻止选择,但会额外更改前景颜色。
<ListBox>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Focusable" Value="False"/>
<!--<Setter Property="IsHitTestVisible" Value="False"/>-->
</Style>
</ListBox.ItemContainerStyle>
</ListBox>注意,选择仍然可以通过使用ListBox属性的代码来设置:例如SelectedIndex="3"
https://stackoverflow.com/questions/46956392
复制相似问题