2011-12-09 152 views
8

我想增加它的項目之間的距離,所以我可以領導我的綁定操作。如何在listview.items之間添加間距?

<ListView Margin="0,22,0,0" x:Name="ListViewImages" MouseLeftButtonDown="ListViewImages_MouseLeftButtonDown" 
     SelectionMode="Extended" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Disabled" local:ListBoxExtention.IsRectSelectionEnabled="True"> 
     <ListView.ItemsPanel> 
      <ItemsPanelTemplate> 
       <WrapPanel Name="WraPanel1" Margin="5" /> 
      </ItemsPanelTemplate> 
     </ListView.ItemsPanel> 
     <ListView.ItemTemplate> 
      <DataTemplate> 
       <Grid> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="5" ></RowDefinition> 
         <RowDefinition Height="150"></RowDefinition> 
         <RowDefinition Height="15" ></RowDefinition> 
         <RowDefinition Height="5" ></RowDefinition> 
        </Grid.RowDefinitions> 
        <Grid.ColumnDefinitions> 
         <ColumnDefinition Width="7" x:Name="columnLeft"></ColumnDefinition> 
         <ColumnDefinition Width="100" x:Name="columnImage"></ColumnDefinition> 
         <ColumnDefinition Width="7" x:Name="columnRight"></ColumnDefinition> 
        </Grid.ColumnDefinitions> 
        <Image Name="Grid_Images" AllowDrop="True" Width="Auto" Height="Auto" Tag="{Binding Id}" Source="{Binding Converter={StaticResource imageConverter}}" Grid.Row="1" Grid.Column="1" 
          DragEnter="Grid_Images_DragEnter" MouseLeftButtonDown="Grid_Images_MouseLeftButtonDown" MouseLeftButtonUp="Grid_Images_MouseLeftButtonUp" 
          MouseMove="Grid_Images_MouseMove" Drop="Grid_Images_Drop" KeyUp="Grid_Images_KeyUp" /> 
        <TextBlock Name="Grid_Descrition" AllowDrop="True" TextAlignment="Center" Text="{Binding Id}" Grid.Row="2" Grid.Column="1"/> 
       </Grid> 

      </DataTemplate> 

     </ListView.ItemTemplate> 
    </ListView> 

回答

2

您可以只需添加一些保證金,以網格

<Grid Margin="5"> 
       <Grid.RowDefinitions> 
        <RowDefinition Height="5" ></RowDefinition> 
        <RowDefinition Height="150"></RowDefinition> 
        <RowDefinition Height="15" ></RowDefinition> 
        <RowDefinition Height="5" ></RowDefinition> 
       </Grid.RowDefinitions> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="7" x:Name="columnLeft"></ColumnDefinition> 
        <ColumnDefinition Width="100" x:Name="columnImage"></ColumnDefinition> 
        <ColumnDefinition Width="7" x:Name="columnRight"></ColumnDefinition> 
       </Grid.ColumnDefinitions> 
       <Image Name="Grid_Images" AllowDrop="True" Width="Auto" Height="Auto" Tag="{Binding Id}" Source="{Binding Converter={StaticResource imageConverter}}" Grid.Row="1" Grid.Column="1" 
         DragEnter="Grid_Images_DragEnter" MouseLeftButtonDown="Grid_Images_MouseLeftButtonDown" MouseLeftButtonUp="Grid_Images_MouseLeftButtonUp" 
         MouseMove="Grid_Images_MouseMove" Drop="Grid_Images_Drop" KeyUp="Grid_Images_KeyUp" /> 
       <TextBlock Name="Grid_Descrition" AllowDrop="True" TextAlignment="Center" Text="{Binding Id}" Grid.Row="2" Grid.Column="1"/> 
      </Grid> 
1

添加ListView.ItemContainerStyle並創建一個Setter應用於任何你喜歡的大小的Margin

16

希望這會節省別人的時間。我發現有多個屬性必須設置爲0才能完全刪除ListView控件中ListViewItems之間的間距。除了邊距和填充之外,我必須將邊框厚度設置爲0.

<ListView.ItemContainerStyle> 
    <Style TargetType="ListViewItem"> 
      <Setter Property="BorderThickness" Value="0"/> 
      <Setter Property="Margin" Value="0"/> 
      <Setter Property="Padding" Value="0"/> 
    </Style> 
</ListView.ItemContainerStyle> 
相關問題