Как установить высоту строки WPF ListView?

У меня есть listView, отображающий несколько текстовых записей. Мне нужно увеличить высоту строк (работая на сенсорном экране, поэтому мне нужны более толстые строки) без увеличения размера шрифта.

Это, вероятно, довольно тривиально, но я понятия не имею и не могу найти много в Google.

Любая помощь приветствуется.


person JohnIdol    schedule 07.08.2009    source источник


Ответы (3)


Вы можете установить высоту всех ListViewItems в ListView, используя ItemContainerStyle:

<ListView>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="Height" Value="50" />
        </Style>
    </ListView.ItemContainerStyle>
</ListView>
person Andy    schedule 07.08.2009

Или вы можете использовать стили, чтобы установить его для всех списков. Здесь в пределах окна:

<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>
person Thomas Sandberg    schedule 07.08.2009
comment
На самом деле это довольно аккуратно. - person Carl R; 07.10.2013

В 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>

В C # Codebehind

    foreach (ListViewItem lv in myListView.Items)
    {
        lv.Height = 30;
    }

Надеюсь, вы уловили идею.

person Henrik P. Hessel    schedule 07.08.2009
comment
ListViewItem не имеет свойства Height. - person Tyler Pantuso; 30.10.2015