Remove Extra “Space” using List View and GridView

自闭症网瘾萝莉.ら 提交于 2021-01-27 19:07:33

问题


So I am using a Grid View inside of a List View and when I run my application I get this weird spacing stuff before the row of my items, between the items, and at the end (can't see in picture), which I want to remove. Here is my 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>

Does anyone know how to remove this? I tried setting the padding to 0 and several other things, but couldn't get it to go away. I bet it is something simple.


回答1:


The easiest way is to set 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>


来源:https://stackoverflow.com/questions/37687218/remove-extra-space-using-list-view-and-gridview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!