在组合框选择中设置透明突出显示?
Set Transparent Highlight in combobox selection?
当用户将鼠标移到某个项目上时,我正在尝试实现组合框的透明突出显示。我需要它是透明的,因为组合框中的每个项目都已经具有在下拉菜单中显示为背景的颜色。
<ComboBox x:Name="comboBox1" HorizontalAlignment="Left" Margin="84,70,0,0" VerticalAlignment="Top" Width="230" FontWeight="ExtraBold">
<ComboBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}">Transparent</SolidColorBrush>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}">Black</SolidColorBrush>
</ComboBox.Resources>
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Style.Triggers>
<DataTrigger Binding="{Binding Value}" Value="Agriculture">
<Setter Property="Background" Value="Green" />
</DataTrigger>
使用此代码,我只会得到覆盖突出显示项目背景的白色,如下所示:
有什么建议吗?
您可以尝试将 SolidColorBrush 的颜色设置为银色或其他颜色,并将其不透明度 属性 设置为小于 1 的值:
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Opacity="0.4" Color="Silver" />
虽然 HighlightBrushKey 不会应用 "over" ComboBoxItems 的默认 SolidColorBrushes。它将替换这些而不是覆盖它们。
当用户将鼠标移到某个项目上时,我正在尝试实现组合框的透明突出显示。我需要它是透明的,因为组合框中的每个项目都已经具有在下拉菜单中显示为背景的颜色。
<ComboBox x:Name="comboBox1" HorizontalAlignment="Left" Margin="84,70,0,0" VerticalAlignment="Top" Width="230" FontWeight="ExtraBold">
<ComboBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}">Transparent</SolidColorBrush>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}">Black</SolidColorBrush>
</ComboBox.Resources>
<ComboBox.ItemContainerStyle>
<Style TargetType="ComboBoxItem">
<Style.Triggers>
<DataTrigger Binding="{Binding Value}" Value="Agriculture">
<Setter Property="Background" Value="Green" />
</DataTrigger>
使用此代码,我只会得到覆盖突出显示项目背景的白色,如下所示:
有什么建议吗?
您可以尝试将 SolidColorBrush 的颜色设置为银色或其他颜色,并将其不透明度 属性 设置为小于 1 的值:
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Opacity="0.4" Color="Silver" />
虽然 HighlightBrushKey 不会应用 "over" ComboBoxItems 的默认 SolidColorBrushes。它将替换这些而不是覆盖它们。