user6262035
user6262035

Reputation:

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

I am trying to figure out how to get rid of the padding below the text in a listview row: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.

Upvotes: 1

Views: 242

Answers (1)

Alex Witkowski
Alex Witkowski

Reputation: 555

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.

Upvotes: 3

Related Questions