UWP 更改 ListView 项目高度

UWP Change ListView Item Height

如何更改 Windows 10 UWP 应用中 ListView 控件中项目的高度?

例如在 UWP 中,以下不会使行高为 20。(WPF 问题可能会提示这一点,但在 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>

您还需要设置 MinHeight 属性:

            <Style TargetType="ListViewItem">
                <Setter Property="Height" Value="20" />
                <Setter Property="MinHeight" Value="20" />
            </Style>

您还可以覆盖数据模板的样式。

<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