WPF ListView - 如何设置所选项目的背景颜色?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1153345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF ListView - how do i set selected item background colour?
提问by monkey_p
I currently have this, but it only work for the foreground colour.
我目前有这个,但它只适用于前景色。
Any help would be apriciated :D
任何帮助都会被感谢:D
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Foreground" Value="Red" />
<Setter Property="Background" Value="Green"/>
</Trigger>
</Style.Triggers>
回答by Nir
This will take care of the background color, maybe it will also help you find the solution for the foreground, this is from http://blogs.msdn.com/wpfsdk/archive/2007/08/31/specifying-the-selection-color-content-alignment-and-background-color-for-items-in-a-listbox.aspx
这将处理背景颜色,也许它还可以帮助您找到前景的解决方案,这是来自http://blogs.msdn.com/wpfsdk/archive/2007/08/31/specifying-the-selection -color-content-alignment-and-background-color-for-items-in-a-listbox.aspx
<Style TargetType="ListBoxItem">
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Green"/>
</Style.Resources>
</Style>