删除Extra" Space"使用List View和GridView

时间:2016-06-07 18:56:42

标签: wpf listview gridview

The space I want to remove between list view items.

所以我在列表视图中使用网格视图,当我运行我的应用程序时,我在项目行之间,项目之间和结束之前得到了这个奇怪的间距内容(无法看到)图片),我想删除。这是我的XAML。

   <ListView x:Name="schemaTableListView"
              Width="600"
              Height="50"
              Margin="0,550,0,0"
              ItemsSource="{Binding phase}">
       <ListView.View>
            <GridView >
                <GridView.ColumnHeaderContainerStyle>
                    <Style TargetType="{x:Type GridViewColumnHeader}">
                        <Setter Property="IsEnabled" Value="False" />
                    </Style>
                </GridView.ColumnHeaderContainerStyle>
                <GridViewColumn Width="300" Header="Source Schema">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Width="300" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Width="300" Header="Source Table">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBox Width="300" />
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>

有谁知道如何删除它?我尝试将填充设置为0和其他几个东西,但无法让它消失。我打赌这很简单。

1 个答案:

答案 0 :(得分:1)

最简单的方法是设置negativ margin

<ListView>
   <ListView.View>
        <GridView >
            <GridView.ColumnHeaderContainerStyle>
                <Style TargetType="{x:Type GridViewColumnHeader}">
                    <Setter Property="IsEnabled" Value="False" />
                </Style>
            </GridView.ColumnHeaderContainerStyle>
            <GridViewColumn Width="300" Header="Source Schema">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBox Width="300" Margin="-6,0" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Width="300" Header="Source Table">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBox Width="300" Margin="-6,0" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>