设置ListBox选中项的背景颜色

[html]  view plain  copy
 
  1. <Style x:Key="UserItemContainerStyle" TargetType="ListBoxItem">  
  2.     <Style.Resources>  
  3.           
  4.         <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightBlue" Opacity=".4"/>  
  5.           
  6.         <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightBlue" Opacity=".4"/>  
  7.     Style.Resources>  
  8.       
  9.     <Style.Triggers>  
  10.         <Trigger Property="IsMouseOver" Value="true">  
  11.             <Setter Property="Background" Value="#efefef"/>  
  12.             <Setter Property="Foreground" Value="Red"/>  
  13.         Trigger>  
  14.         <Trigger Property="IsFocused" Value="true">  
  15.             <Setter Property="Background" Value="Coral"/>  
  16.             <Setter Property="Foreground" Value="Red"/>  
  17.         Trigger>  
  18.     Style.Triggers>  

  1. Style>  

原文地址:http://blog.csdn.net/leftfist/article/details/27544233

其他方法:https://www.mgenware.com/blog/?p=180

你可能感兴趣的:(WPF)