我抓住了组合框的整个模板进行一些修改。ComboBoxItem 的样式是这样的:
<Style x:Key="ComboBoxItemStyle" TargetType="{x:Type ComboBoxItem}">
<Setter Property="OverridesDefaultStyle" Value="True"></Setter>
<Setter Property="Background" Value="{DynamicResource StandardBlackBrush}"></Setter>
<Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBoxItem}">
<Border x:Name="Bd" BorderBrush="{DynamicResource StandardBlackBrush}" BorderThickness="3" SnapsToDevicePixels="true" >
<ContentPresenter x:Name="Cp" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsHighlighted" Value="true">
<Setter TargetName="Bd" Property="BorderBrush" Value="{DynamicResource StandardFocusRectangleBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style >
这会产生非常小的组合框项目,它们只是内容的高度/宽度,它只是一个文本字符串。为了使这些项目更大,我在 ContentPresenter 中添加了一个边距,它看起来很好:
<ContentPresenter Margin="20,10,20,10" x:Name="Cp" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
但是,鼠标点击仍然必须在文本区域内。在文本之外但在边框内单击鼠标会关闭弹出窗口但不进行选择。这是我的问题。