Wpf 如何增加显示项组合框的填充?

Wpf 如何增加显示项组合框的填充?,wpf,xaml,templates,combobox,itemscontrol,Wpf,Xaml,Templates,Combobox,Itemscontrol,我想编写组合框的XAML模板,以增加项目之间的空格/填充。 我搜索了这个,但几乎以ItemsPresenter结束: <ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>

我想编写组合框的XAML模板,以增加项目之间的空格/填充。 我搜索了这个,但几乎以ItemsPresenter结束:

<ItemsPresenter x:Name="ItemsPresenter"
                KeyboardNavigation.DirectionalNavigation="Contained"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>

如何使用此模板格式化项目(边框、填充、字体…)? 请提供帮助。

您可以使用将样式应用于设置属性(如填充)的:

<ComboBox ItemsSource="{Binding}">
    <ComboBox.ItemContainerStyle>
        <Style TargetType="ComboBoxItem">
            <Setter Property="Padding" Value="5"/>
            <Setter Property="BorderBrush" Value="Blue"/>
            <Setter Property="BorderThickness" Value="2"/>
            <Setter Property="FontFamily" Value="Courier New"/>
        </Style>
    </ComboBox.ItemContainerStyle>
</ComboBox>

如果希望它应用于所有组合框,可以在资源中为ComboBoxItem创建隐式样式:

<Window.Resources>
    <Style TargetType="ComboBoxItem">
        <Setter Property="Padding" Value="5"/>
    </Style>
</Window.Resources>
<StackPanel>
    <ComboBox ItemsSource="{Binding}"/>
    <ComboBox ItemsSource="{Binding}"/>
</StackPanel>

我也需要这个!期待你们的消息。