Nam*_* VU 7 wpf xaml templates combobox itemscontrol
我想编写一个组合框的XAML模板来增加项目之间的空格/填充.我搜索了这个,但几乎最终得到了ItemsPresenter:
<ItemsPresenter x:Name="ItemsPresenter"
                KeyboardNavigation.DirectionalNavigation="Contained"
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
如何使用此模板格式化项目(边框,填充,字体...)?请帮忙.
Qua*_*ter 10
您可以使用ItemContainerStyle将样式应用于设置填充等属性的ComboBoxItem:
<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>