How to set WPF ListView row height?
Asked Answered
D

3

34

I've got a listView displaying a few text records. I need to increase the height of rows (working on a touch screen so I need thicker rows) without increasing the font size.

This is probably pretty trivial but I have no clue and can't find much on google.

Any help appreciated.

Devalue answered 7/8, 2009 at 10:45 Comment(0)
B
82

You can set the height of all ListViewItems in a ListView by using ItemContainerStyle:

<ListView>
    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="Height" Value="50" />
        </Style>
    </ListView.ItemContainerStyle>
</ListView>
Bondwoman answered 7/8, 2009 at 11:2 Comment(0)
P
10

Or you could use styles to set it for all listviews. Here scoped to within a 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">

    <Window.Resources>
        <Style TargetType="ListViewItem">
            <Setter Property="Height" Value="100"/>
        </Style>
    </Window.Resources>
    ...
</Window>
Prestige answered 7/8, 2009 at 11:12 Comment(1)
This is actually quite neat.Decorous
N
3

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

In C# Codebehind

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

Hope you getting the Idea.

Neural answered 7/8, 2009 at 11:0 Comment(1)
ListViewItem does not have a Height property.Uncloak

© 2022 - 2024 — McMap. All rights reserved.