1 <ListBox> 2 <!-- 数据 --> 3 <ListBoxItem>AAAA</ListBoxItem> 4 <ListBoxItem>BB</ListBoxItem> 5 <ListBoxItem>CCCC</ListBoxItem> 6 <!-- 设置ListBoxItem样式 --> 7 <ListBox.ItemContainerStyle> 8 <Style TargetType="ListBoxItem"> 9 <!-- 设置控件模板 --> 10 <Setter Property="Template"> 11 <Setter.Value> 12 <ControlTemplate TargetType="ListBoxItem"> 13 <Border Background="{TemplateBinding Background}"> 14 <ContentPresenter HorizontalAlignment="{TemplateBindingHorizontalContentAlignment}" 15 VerticalAlignment="{TemplateBinding VerticalContentAlignment}" 16 TextBlock.Foreground="{TemplateBinding Foreground}"/> 17 </Border> 18 </ControlTemplate> 19 </Setter.Value> 20 </Setter> 21 <!-- 设置触发器 --> 22 <Style.Triggers> 23 <Trigger Property="IsSelected" Value="true"> 24 <Setter Property="Background" Value="Black"/> 25 <Setter Property="Foreground" Value="White"/> 26 </Trigger> 27 <Trigger Property="IsMouseOver" Value="true"> 28 <Setter Property="Background" Value="LightGreen"/> 29 <Setter Property="Foreground" Value="Red"/> 30 </Trigger> 31 </Style.Triggers> 32 </Style> 33 </ListBox.ItemContainerStyle> 34 </ListBox>