【问题标题】:How to set WPF ListView row height?如何设置 WPF ListView 行高?
【发布时间】:2010-11-17 15:54:27
【问题描述】:

我有一个 listView 显示一些文本记录。我需要在不增加字体大小的情况下增加行高(在触摸屏上工作,所以我需要更粗的行)。

这可能是微不足道的,但我不知道,在谷歌上也找不到太多。

任何帮助表示赞赏。

【问题讨论】:

    标签: wpf listview layout row-height


    【解决方案1】:

    您可以使用ItemContainerStyle 设置ListView 中所有ListViewItems 的高度:

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

    【讨论】:

      【解决方案2】:

      或者您可以使用样式为所有列表视图设置它。这里的范围是在一个窗口内:

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

      【讨论】:

      • 这其实很整洁。
      【解决方案3】:

      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# 代码隐藏中

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

      希望你能得到这个想法。

      【讨论】:

      • ListViewItem 没有 Height 属性。
      猜你喜欢
      • 2012-05-09
      • 2014-11-10
      • 1970-01-01
      • 1970-01-01
      • 2011-01-18
      • 2012-11-29
      • 1970-01-01
      • 1970-01-01
      • 2012-11-22
      相关资源
      最近更新 更多