UWP 更改 ListView 项高度

13

如何在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个回答

21

你还需要设置 MinHeight 属性:

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

1
现在移除了 Height 属性。 - 27k1

4
你可以覆盖数据模板的样式。
<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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接