我有一个ListView,里面显示了几个文本记录。我需要增加行高(因为我是在触摸屏上工作,所以我需要更厚的行),但不想增加字体大小。
这可能非常琐碎,但我一点头绪也没有,在谷歌上也找不到太多相关信息。
任何帮助都将不胜感激。
我有一个ListView,里面显示了几个文本记录。我需要增加行高(因为我是在触摸屏上工作,所以我需要更厚的行),但不想增加字体大小。
这可能非常琐碎,但我一点头绪也没有,在谷歌上也找不到太多相关信息。
任何帮助都将不胜感激。
通过使用 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>
<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>
在C#的代码后台
foreach (ListViewItem lv in myListView.Items)
{
lv.Height = 30;
}