UWP Change ListView Item Height
Asked Answered
H

2

14

How do you change the height of items in a ListView control in a Windows 10 UWP app?

For example in UWP, the following does not make the row height 20. (WPF questions might suggest this, but it does not seem to work in the UWP XAML):

        <ListView x:Name="listView" IsItemClickEnabled="True">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="Height" Value="20" />
                </Style>
            </ListView.ItemContainerStyle>

            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel Height="20">
                        <TextBlock Text="{Binding Title}" TextWrapping="NoWrap" Foreground="White" Height="20"/>
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
Hennebery answered 29/6, 2016 at 21:20 Comment(0)
H
22

You need to also set the MinHeight property:

            <Style TargetType="ListViewItem">
                <Setter Property="Height" Value="20" />
                <Setter Property="MinHeight" Value="20" />
            </Style>
Heresiarch answered 29/6, 2016 at 23:45 Comment(1)
Nowadays remove the Height property.Boynton
S
4

You can also override the style of your data template.

<Page.Resources>
    <ResourceDictionary>
        <ResourceDictionary.ThemeDictionaries>
            <ResourceDictionary x:Key="Default">
                <x:Double x:Key="ListViewItemMinHeight">20</x:Double>
                <x:Double x:Key="ListViewItemHeight">20</x:Double>
            </ResourceDictionary>
            <ResourceDictionary x:Key="HighContrast">
            </ResourceDictionary>
        </ResourceDictionary.ThemeDictionaries>
    </ResourceDictionary>
</Page.Resources>

http://loekvandenouweland.com/content/UWP-lightweight-listview-styling.html

Supat answered 1/12, 2017 at 12:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.