简体   繁体   English

是否可以在鼠标悬停时突出显示列表框中的不可选项?

[英]Is it possible to highlight the unselectable item in the list box on mouse hover?

I created a list box with item templates and linked it to a list below is a simplified version of it. 我创建了一个带有项目模板的列表框,并将其链接到下面的列表是它的简化版本。 These items are now selectable and highlight on mouse hover but I want to make them unselectable. 这些项目现在可以选择并在鼠标悬停时突出显示,但我想让它们无法选择。 if I change the focusable property in style to false then it is not highlighted on mouse hover. 如果我将样式中的focusable属性更改为false,则鼠标悬停时不会突出显示该属性。

<ListBox x:Name="ListBox1" x:Uid="ListBox1" 
  ItemsSource="{Binding myList}">
  <ListBox.ItemTemplate>
  .
  .
  .
  </ListBox.ItemTemplate>  
</ListBox>

The easiest way would be to add a PreviewMouseDown handler and return true to prevent them from being clicked on. 最简单的方法是添加一个PreviewMouseDown处理程序并返回true以防止它们被单击。 They would still be selectable with the keyboard though. 尽管如此,它们仍然可以通过键盘选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM