更改组合框项目的高亮颜色WPF
我一直在寻找小时,试图找出如何更改组合框项目的高亮颜色(NOT MouseOver)。我有一个可编辑的组合框,用于搜索绑定到它的列表中的元素。在列表中键入元素名称将突出显示组合框下拉列表中的元素。但该元素突出了一个默认的“浅灰色”,这是很难看到...更改组合框项目的高亮颜色WPF
我试图重写这篇文章中所描述的默认高亮色彩:Set ComboBox selected item highlight color,没有运气。
再次发生这种情况不是鼠标悬停在盒子中搜索或使用键盘上的向上/向下箭头键导航列表。我也考虑过可能在查看键盘焦点属性,但不知道如何在模板中实现它。让我知道,如果需要,我可以发布模板。
我刚刚为这个组合框启动了一个全新的模板,所以它应该都很干净。我只是不能确定我应该瞄准什么元素/触发器/边界。
有人对此有所了解吗?
找到这个问题的答案将关闭此文章在这里的工作:Set style on ComboBoxItem from template for ComboBox
我申请修改ComboBoxItem模板,我的“编辑ComboBox”的模板。您可以在下面看到这里,我在IsEditable风格触发增加了一个“ItemContainerStyle”属性:
<Style x:Key="CmbRoundedAutoComplete" TargetType="{x:Type ComboBox}">
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
<Setter Property="Background" Value="{StaticResource ComboBox.Static.Background}"/>
<Setter Property="BorderBrush" Value="{StaticResource ComboBox.Static.Border}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="Padding" Value="6,3,5,3"/>
<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
<Setter Property="Template" Value="{StaticResource ComboBoxTemplate}"/>
<Style.Triggers>
<Trigger Property="IsEditable" Value="true">
<Setter Property="IsTabStop" Value="false"/>
<Setter Property="Padding" Value="2"/>
<Setter Property="Template" Value="{StaticResource ComboBoxEditableTemplate}"/>
<!-- Added this line here -->
<Setter Property="ItemContainerStyle" Value="{DynamicResource ComboBoxItemShieldStyle}" />
</Trigger>
</Style.Triggers>
</Style>
有一个MultiTrigger位于自定义“ItemContainerStyle”控件模板(重要的是要注意的一部分,这是样式不是实际的ControlTemplate。)。 ControlTemplate元素驻留在样式中。
您可以通过手动将ComboBoxItem添加到XAML中现有的ComboBox并生成一个模板来生成一个“ComboboxItem”模板。
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True"/>
<Condition Property="IsMouseOver" Value="False"/>
<Condition Property="IsKeyboardFocused" Value="False"/>
</MultiTrigger.Conditions>
<!-- ANSWER IS HERE Change color on the 2 below lines for border & background -->
<Setter Property="Background" TargetName="Bd" Value="#D1E8FF"/>
<Setter Property="BorderBrush" TargetName="Bd" Value="#66A7E8"/>
</MultiTrigger>
你可以在上面的代码中看到我曾经评论说:“答案就在这里”,您可以更改已通过在组合框中场无论是打字选择或导航到它与该项目的背景颜色箭头键。
在“结果”(以红色文字显示)中,当前项目的“背景”是相当蓝色的颜色,而不是上述原始问题中的蹩脚灰色...
最终结果:
我们可以有一个解决方案来突出显示可能项目的一部分,例如:当我输入“办公室”时,有3名候选人(见上述图片),3名候选人的红色文字“办公室”是红色的? –