wpf中鼠标放到combobox的下拉菜单选项上,该选项就会改变背景颜色,怎么取消变色?
只需要”编辑模板“→”编辑副本“→系统就自动生成了一大串样式→你只需要找到下面样式替换就OK啦!
<!-- 下拉框只读切换按钮 -->
<Style x:Key="ComboBoxReadonlyToggleButton" TargetType="{x:Type ToggleButton}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Focusable" Value="false"/>
<Setter Property="ClickMode" Value="Press"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Border x:Name="Chrome"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}"
CornerRadius="3"
BorderThickness="0"
Margin="0,0,-0.2,0"
SnapsToDevicePixels="true">
<Grid HorizontalAlignment="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
<Path x:Name="Arrow"
Data="{StaticResource DownArrowGeometry}"
Fill="Black"
HorizontalAlignment="Center"
Margin="1,1,0,0"
VerticalAlignment="Center"/>
</Grid>
</Border>
<ControlTemplate.Triggers>
<!-- 默认的按钮样式 -->
<Trigger Property="IsEnabled" Value="true">
<Setter Property="Fill" TargetName="Arrow" Value="#AFAFAF"/>
<Setter Property="Background" TargetName="Chrome" Value="{StaticResource ButtonNormalBackground}"/>
</Trigger>
<!-- 鼠标经过时的样式 -->
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" TargetName="Chrome" Value="{StaticResource ButtonMouseOverBackground}"/>
</Trigger>
<!-- 鼠标获得焦点时的样式 -->
<Trigger Property="IsFocused" Value="true">
<Setter Property="Background" TargetName="Chrome" Value="{StaticResource ButtonFocusedBackground}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
2011-08-08