UWP更改ListView项目高度

时间:2016-06-29 21:20:05

标签: listview win-universal-app uwp listviewitem

如何在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>

2 个答案:

答案 0 :(得分:16)

您还需要设置MinHeight属性:

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

答案 1 :(得分:2)

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

<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