2012-03-25 72 views
6

我在设计一个listBox。我试图清除边距,所以我意识到它,我将样式的填充设置为0(左填充)。如何去除ListBoxItem周围的小填充?

但我仍然可以看到它的一些边际,我需要没有余量呢?你知道哪个是问题吗?

enter image description here

  <ListBox ItemsSource="{Binding Partitions}"> 
       <ListBox.ItemsPanel> 
        <ItemsPanelTemplate> 
         <Canvas /> 
        </ItemsPanelTemplate> 
       </ListBox.ItemsPanel> 

       <ListBox.ItemContainerStyle> 
        <Style TargetType="ListBoxItem"> 
         <Setter Property="Padding" Value="0"/> 
         <Setter Property="Canvas.Top"> 
          ... 
         </Setter> 
       </Style> 
       </ListBox.ItemContainerStyle> 

我的意思是,我可以看到周围的项目额外的空间,我不能处理它修改为0

+1

什么是您的完整代码?我插入到一个基本的网格,并没有得到这个问题 – 2012-03-25 05:16:12

+1

可能[重复](http://stackoverflow.com/questions/1351605/where-are-the-margins-padding-set-on-a-wpf-listview -网格视图)。看到问题中的第二个答案。 – NVM 2012-03-25 05:52:35

回答

3

即填充是硬编码的default templateListBox,你需要覆盖它或在运行时修改它(我会推荐而不是)。

<ControlTemplate TargetType="{x:Type ListBox}"> 
    <Border Name="Bd" 
      Background="{TemplateBinding Background}" 
      BorderBrush="{TemplateBinding BorderBrush}" 
      BorderThickness="{TemplateBinding BorderThickness}" 
      SnapsToDevicePixels="true" 
      Padding="1"> <!-- Here -->