如何增加padding显示的项目组合框? [英] How to increase padding displayed items combobox?
本文介绍了如何增加padding显示的项目组合框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想写一个组合框的XAML模板来增加项目之间的空格/填充。
我搜索这个,但几乎结束了ItemsPresenter:
I want to write XAML template of a combobox to increase the spaces/padding between items. I searched for this but almost end up with the ItemsPresenter:
<ItemsPresenter x:Name="ItemsPresenter"
KeyboardNavigation.DirectionalNavigation="Contained"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
如何使用此模板格式化项目(边框,填充,字体...)
请帮助。
How can I format the item (border, padding, font...) using this template? Please help.
推荐答案
您可以使用 ItemContainerStyle 将样式应用到 ComboBoxItems ,用于设置如填充的属性:
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>
如果你想要应用到所有组合框,你可以为ComboBoxItem创建一个隐式样式您的资源:
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>
这篇关于如何增加padding显示的项目组合框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文