2010-07-25 69 views
6

我想寫一個組合框的XAML模板來增加項目之間的空白/填充。 我搜索了這一點,但幾乎結束與ItemsPresenter:如何增加填充顯示項目組合框?

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

如何設置格式使用此模板的項目(邊框,邊距,字體...)? 請幫忙。

+0

我也需要這個!期待聽到你們所有人的聲音。 – 2010-07-25 10:37:54

回答

8

您可以使用ItemContainerStyle將樣式應用到設置如padding屬性的ComboBoxItems

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