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