ListBoxItem 取消hover高亮,仅显示选中高亮;其他控件与此类似
<Style TargetType="{x:Type ListBoxItem}"> <Setter Property="Background" Value="Transparent"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListBoxItem}"> <Border Background="{TemplateBinding Background}" BorderThickness="1"> <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/> </Border> </ControlTemplate> </Setter.Value> </Setter> <Style.Triggers> <!--<Trigger Property="IsSelected" Value="True"> <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.HighlightColor}}"/> </Trigger>--> <DataTrigger Binding="{Binding IsSelected, RelativeSource={RelativeSource Self}}" Value="true"> <Setter Property="Background" Value="#FFBFEFFF"/> </DataTrigger> </Style.Triggers> </Style>
上述xml中注释也能实现选中高亮,但是由于其为系统颜色,不太符合测试要求。
标签:hover,高亮,取消,选中,ListBoxItem,WPF From: https://www.cnblogs.com/chengcanghai/p/17485643.html