How do I get rid of unwanted padding in a Listview row

拈花ヽ惹草 提交于 2019-12-25 09:07:29

问题


I am trying to figure out how to get rid of the padding below the text in a listview row:

And my markup for the Listview:

        <ListView 
            ItemsSource ="{Binding AllowedApplicants}"
            Height="250" 
            Width="219"
            VerticalAlignment="Top"
            Grid.Row="3"
            Grid.Column="1"
            Grid.ColumnSpan="2"
            Margin="20,5"
            BorderBrush="Bisque" 
            BorderThickness="2">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding}" Padding="5,5" />
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

I can't figure out where this extra padding (red arrow) is coming from. The properties for the row's padding and margins defaults to zero all around. I added the five to keep the text off the borders. The list view row seems to have a default Height which cannot be adjusted.


回答1:


Try adding

 <ListView.ItemContainerStyle>
    <Style TargetType="ListViewItem">
        <Setter Property="MinHeight" Value="0"/>
    </Style>
</ListView.ItemContainerStyle>

to your List View or use Live Property Explorer and Live Visual Tree Viewer from Visual Studio and peek into the ListViewItem.



来源:https://stackoverflow.com/questions/40694359/how-do-i-get-rid-of-unwanted-padding-in-a-listview-row

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