XAML ListView ItemContainer Height

2019-07-08 03:07发布

问题:

I want to Change the Height of the ItemContainer and not the Heightof the Item itself the Container is in a ListView

What I want to Change:

To Something like this:

The structur of the Code Looks like this:

 <ListView>
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition/>
                                        <ColumnDefinition/>
                                    </Grid.ColumnDefinitions>
                                    <TextBlock Text="{Binding A}" Grid.Column="0"/>
                                    <TextBlock Text="{Binding B}" Grid.Column="1"/>
                                </Grid>
                            </DataTemplate>
                        </ListView.ItemTemplate>
                    </ListView>

Hope for some help

回答1:

You need to change the MinHeight of all ListViewItem elements that appear in your ListView. You can achieve this by using a Style.

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

    <TextBlock Text="Hello"/>
    <TextBlock Text="World"/>
</ListView>

Using Padding with this method is also a good idea as you do not want each list view item to be too thin.