Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何设置WPF ListView行高?_Wpf_Listview_Layout_Row Height - Fatal编程技术网

如何设置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>