How to increase padding displayed items combobox?

人走茶凉 提交于 2019-12-05 05:42:24

You can use ItemContainerStyle to apply a style to the ComboBoxItems that sets properties such as padding:

<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>

If you want it to apply to all combo boxes, you could instead create an implicit style for ComboBoxItem in your Resources:

<Window.Resources>
    <Style TargetType="ComboBoxItem">
        <Setter Property="Padding" Value="5"/>
    </Style>
</Window.Resources>
<StackPanel>
    <ComboBox ItemsSource="{Binding}"/>
    <ComboBox ItemsSource="{Binding}"/>
</StackPanel>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!