如何禁用列表框上的突出显示但保留选择?
我无法找到如何不允许我的列表框突出显示所选项目。我知道我没有添加触发器来突出显示该项目。
<ListBox Name="CartItems" ItemsSource="{Binding}"
ItemTemplate="{StaticResource TicketTemplate}"
Grid.Row="3" Grid.ColumnSpan="9" Background="Transparent"
BorderBrush="Transparent">
</ListBox>
I am having trouble finding how to not allow my ListBox to highlight the item selected. I know that I didn't add a trigger to highlight the item.
<ListBox Name="CartItems" ItemsSource="{Binding}"
ItemTemplate="{StaticResource TicketTemplate}"
Grid.Row="3" Grid.ColumnSpan="9" Background="Transparent"
BorderBrush="Transparent">
</ListBox>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
迟到的答案,但有一个更好、更简单的解决方案:
这允许您拥有一个看起来像项目控件的 LisBox,但支持选择。
编辑:如何它的工作原理
这会改变“系统的颜色”,换句话说,您的 Windows 主题,仅适用于此 ListBox 及其子项(我们实际上希望以
ListboxItem
为目标)。例如,悬停在
ListboxItem
上通常会为其提供深蓝色背景,但这里我们将其设置为透明 (HighlightBrushKey)。编辑(2016 年 6 月 30 日):
看来对于最新的Windows版本来说这已经不够了,你还需要重新定义
InactiveSelectionHighlightBrushKey
感谢评论中的@packoman
Late answer, but there's a much better and simpler solution:
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
Thanks to @packoman in the comments
完全删除突出显示感觉很奇怪,因为您不知道是否选择了任何内容,但这里有一个使用
WhiteSmoke
(非常微妙)而不是Blue< 的控件模板版本/代码>
removing the highlighting completely feels very odd, as you dont know if you've selected anything, but here's a version of the control template that uses
WhiteSmoke
(which is very subtle) instead ofBlue
这对我有用。
here's what worked for me.
在“属性”选项卡中,有一个“启用”字段,其中有 2 个选项:true 和 false。通过将其设置为 false,列表框将保持白色并且选择不可用。刚刚想通了这一点!
In the Properties tab, there is an Enabled Field with 2 options, true and false. By turning this to false, the Listbox remains white and selection is not avaliable. Just figured this out!
我正在谈论我在 WP8 应用程序中所做的一个技巧。
我在其上方添加了一个透明框架图像(可以看到图像的边框,可以将其想象为相框)。滚动功能正常,任何操作事件都会触发,只是列表框项目不再被选择。
我想这也可以与设置为“填充”的完全透明图像一起使用。
I'm talking about a trick I did in my WP8 app.
I added a transparent frame image above it (the image's border was seen, think of it like a picture frame). The scroll was functional, any manipulation event was firing just that the Listbox items weren't selected anylonger.
I guess this could work with a full transparent image set to Fill as well.
您必须重新模板
ListBoxItem
。在默认模板中,它有一个触发器,当IsSelected
属性为true
时,它会突出显示自身。您只需创建一个没有该触发器的模板即可。You will have to re-template
ListBoxItem
. In the default template, it has a trigger that highlights itself whenIsSelected
property istrue
. You just have to create a template that does not have that trigger.我认为您需要为 ListBoxItem 创建一个自定义控件模板,并包含在选择该项目时将背景颜色更改为“透明”的触发器。以下是如何执行此操作的示例:
I think you need to create a custom control template for the ListBoxItem, and include the trigger to change the background color to "Transparent" when the item is selected. Here is an example of how you can do this: