如何设置WPF ListView行高?
我有一个列表视图显示了一些文本记录。我需要增加行的高度(在触摸屏上工作,所以我需要更厚的行),而不增加字体大小 这可能是相当琐碎的,但我没有线索,也无法在谷歌上找到太多如何设置WPF ListView行高?,wpf,listview,layout,row-height,Wpf,Listview,Layout,Row Height,我有一个列表视图显示了一些文本记录。我需要增加行的高度(在触摸屏上工作,所以我需要更厚的行),而不增加字体大小 这可能是相当琐碎的,但我没有线索,也无法在谷歌上找到太多 感谢您的帮助。在XAML中 <Window x:Class="WpfApplication2.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schema
感谢您的帮助。在XAML中
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Grid>
<StackPanel>
<ListView x:Name="myListView">
<ListViewItem Height="50">Test</ListViewItem>
<ListViewItem Height="30">Test</ListViewItem>
</ListView>
</StackPanel>
</Grid>
</Window>
希望您能理解。您可以使用
ItemContainerStyle
在ListView
中设置所有ListViewItems
的高度:
<ListView>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Height" Value="50" />
</Style>
</ListView.ItemContainerStyle>
</ListView>
或者您可以使用样式为所有列表视图设置它。此处的范围是在窗口内:
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<Style TargetType="ListViewItem">
<Setter Property="Height" Value="100"/>
</Style>
</Window.Resources>
...
</Window>
...
这实际上相当整洁。ListViewItem没有Height属性。
<Window x:Class="WpfApplication2.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Window.Resources>
<Style TargetType="ListViewItem">
<Setter Property="Height" Value="100"/>
</Style>
</Window.Resources>
...
</Window>