【WPF】修改ListBox的Item的样式<ListBox>
<!-- 数据 -->
<ListBoxItem>AAAA</ListBoxItem>
<ListBoxItem>BB</ListBoxItem>
<ListBoxItem>CCCC</ListBoxItem>
<!-- 设置ListBoxItem样式 -->
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<!-- 设置控件模板 -->
<Setter Property="Template">borderbox
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Background="{TemplateBinding Background}">
<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="LightPink"/>
<Setter Property="Foreground" Value="White"/>
</Trigger>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="LightGreen"/>
<Setter Property="Foreground" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论