如何禁用高亮列表框,但保持的选择? [英] How to disable highlighting on listbox but keep selection?

查看:474
本文介绍了如何禁用高亮列表框,但保持的选择?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法找到如何不能让我的列表框突出选择的项目。我知道,我没有添加一个触发器来选择项目。我仍然相当新的WPF =)

谢谢!

 <列表框名称=CartItems的ItemsSource ={结合}
         的ItemTemplate ={StaticResource的TicketTemplate}
         Grid.Row =3Grid.ColumnSpan =9背景=透明
         BorderBrush =透明>
< /列表框>


解决方案

晚的答案,但有一个更好更简单的解决方案:

 <&ListBox中的GT;
   < ListBox.Resources>
      <的SolidColorBrush X:键={X:静态SystemColors.HighlightBrushKey}颜色=透明/>
      <的SolidColorBrush X:键={X:静态SystemColors.HighlightTextBrushKey}颜色=黑/>
      <的SolidColorBrush X:键={X:静态SystemColors.ControlBrushKey}颜色=透明/>
   < /ListBox.Resources>
< /列表框>

这可以让你有一个LisBox,看起来就像一个ItemsControl,但可供选择的支持。

编辑: 如何的工作原理

这改变系统的颜色,换句话说,你的Windows主题,只为这个ListBox和它的孩子(我们真正想要的目标的 ListBoxItem的)。

例如徘徊在 ListBoxItem的通常给它一个深蓝色的背景,但在这里我们将其设置为透明(HighlightBrushKey)。

修改(2016年6月30日):

这似乎是最新的Windows版本,这是不够的了,你还需要重新定义 InactiveSelectionHighlightBrushKey

 <的SolidColorBrush X:键={X:静态SystemColors.InactiveSelectionHighlightBrushKey}颜色=透明/>

由于评价@packoman

I am having trouble finding how to not allow my list box to highlight the item selected. I know that I didn't add a trigger to highlight the item. I'm still fairly new to WPF =)

Thanks!

<ListBox Name="CartItems" ItemsSource="{Binding}"
         ItemTemplate="{StaticResource TicketTemplate}" 
         Grid.Row="3" Grid.ColumnSpan="9" Background="Transparent"
         BorderBrush="Transparent">
</ListBox>

解决方案

Late answer, but there's a much better and simpler solution:

<ListBox>
   <ListBox.Resources>
      <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
      <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
      <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />  
   </ListBox.Resources>
</ListBox>

This allows you to have a LisBox that looks just like an itemscontrol, but has support for selection.

Edit: How it works
This alters "colors of the system", in other words your windows theme, only for this ListBox and its children (we actually want to target the ListboxItem).

For example hovering a ListboxItem usually gives it a deep blue background, but here we set it to transparent (HighlightBrushKey).

Edit (30 June 2016):
It seems for latest Windows version this is not enough anymore, you also need to redefine InactiveSelectionHighlightBrushKey

<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="Transparent" />

Thanks to @packoman in the comments

这篇关于如何禁用高亮列表框,但保持的选择?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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