WPF ListView - 如何设置所选项目背景颜色?

mon*_*y_p 14 wpf listview background

我目前有这个,但它只适用于前景色.

任何帮助都会受到影响:D

<Style.Triggers>
    <Trigger Property="IsSelected" Value="true">
        <Setter Property="Foreground" Value="Red" />
        <Setter Property="Background" Value="Green"/> 
    </Trigger>
</Style.Triggers>
Run Code Online (Sandbox Code Playgroud)

Nir*_*Nir 28

这将照顾背景颜色,也许它也可以帮助您找到前景的解决方案,这是来自http://blogs.msdn.com/wpfsdk/archive/2007/08/31/specifying-the-selection -color-内容对准和背景颜色换项-IN-A-listbox.aspx

<Style TargetType="ListBoxItem">
    <Style.Resources>
        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Green"/>
    </Style.Resources>
</Style>
Run Code Online (Sandbox Code Playgroud)