1、样式代码如下
<ListBox HorizontalAlignment="Center" VerticalAlignment="Center" MinWidth="100" Margin="20">
<!-- 数据 -->
<ListBoxItem>AAAAAA</ListBoxItem>
<ListBoxItem>BBBBBB</ListBoxItem>
<ListBoxItem>CCCCCC</ListBoxItem>
<ListBoxItem>DDDDDD</ListBoxItem>
<ListBoxItem>EEEEEE</ListBoxItem>
<!-- 设置ListBoxItem样式 -->
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<!-- 设置控件模板 -->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Background="{TemplateBinding Background}" Margin="10 5 10 5">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
TextBlock.Foreground="{TemplateBinding Foreground}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<!-- 设置触发器 -->
<Style.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter Property="Background" Value="Teal"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="YellowGreen"/>
<Setter Property="Foreground" Value="OrangeRed"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
**************************************************************************************************************
2、效果图
**************************************************************************************************************