ListView 中的动态突出显示颜色
如何使背景突出显示颜色依赖于 ListViewItem 的某些属性?
How can I make background highlight color dependent on some property of ListViewItem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是人们经常询问的问题。实际上,由于某些原因,当在 ListView 或 ListBox 中选择一项时,背景颜色不会改变。这有点棘手。事实上,您需要覆盖项目模板绑定到的静态颜色资源的值。因此,要更改项目的突出显示颜色,您必须这样做:
这是更详细的解释:ListBoxItem 的触发器
This is an issue that people often ask for. Actually, for some reasons, when an item is selected in a ListView or ListBox, the Background color is not the one that is changed. It is a bit more tricky. In fact you need to override the value of the static color resources to which the item template is bound. So to change the higlighting colors of the items you have to do like this:
Here is a more developed explanation: Trigger for ListBoxItem
编辑:
要更改所选背景,您必须覆盖 ListViewItem 的模板。
请参阅此... http://msdn.microsoft .com/en-us/library/ms788717(v=vs.90).aspx。
将
{StaticResource SelectedBackgroundBrush}
替换为模板中您首选的背景画笔。要根据控件模板不依赖的任何其他属性更改背景,您可以使用触发器...
我希望这能回答您的问题。
EDIT:
For changing selected background, you will have to override the ListViewItem's Template.
See this... http://msdn.microsoft.com/en-us/library/ms788717(v=vs.90).aspx.
Replace the
{StaticResource SelectedBackgroundBrush}
with your preferred background brush in the template.To change backgrounds based on ANY other property that the control template does not rely upon, You can use triggers ...
I hope this answers your question.