Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UWP Change ListView Item Height

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>
like image 700
John Kurtz Avatar asked Jun 29 '16 21:06

John Kurtz


2 Answers

You need to also set the MinHeight property:

            <Style TargetType="ListViewItem">
                <Setter Property="Height" Value="20" />
                <Setter Property="MinHeight" Value="20" />
            </Style>
like image 65
Markus Hütter Avatar answered Nov 16 '22 16:11

Markus Hütter


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

like image 4
Philippe Matray Avatar answered Nov 16 '22 15:11

Philippe Matray