XAML ListView ItemContainer Height

2019-07-08 02:15发布

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:

enter image description here

To Something like this:

enter image description here

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条回答
2楼-- · 2019-07-08 03:00

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.

查看更多
登录 后发表回答