【问题标题】:ListView minimal height cannot be changedListView 最小高度不能更改
【发布时间】:2018-01-20 13:56:32
【问题描述】:

我在 UWP 中有一个简单的ListView。我希望列表元素的高度小于默认高度。看来我可以分配一个更高的值,但有一个无法覆盖的最小值。

我尝试设置负填充和负边距,降低字体大小和对齐方式,但无济于事。

以下是我正在使用的代码。

<ListView x:Name="listView" Margin="0,10,0,0" IsItemClickEnabled="False">
    <ListView.ItemTemplate>
        <DataTemplate x:DataType="local:Element">
            <StackPanel Orientation="Horizontal" Height="10" Margin="0" Padding="0">
                <TextBlock Text="{Binding Name}" VerticalAlignment="Center" Padding="0" Margin="0" FontWeight="Bold"/>
                <TextBlock Text="{Binding Value}" VerticalAlignment="Center" Padding="0" Margin="5,0,0,0"/>
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

将StackPanel 高度设置为较低的值只会切断文本(或文本面板),但项目高度保持不变。不过,设置为更高的值会增加项目的高度。

有人对此有解释或解决方法吗?

【问题讨论】:

    标签: c# xaml listview uwp uwp-xaml


    【解决方案1】:

    我找到了解决办法。更改ItemContainerStyle 并将MinHeight 属性设置为目标值。

    <ListView.ItemContainerStyle>
        <Style TargetType="ListViewItem">
            <Setter Property="MinHeight" Value="32"/>
        </Style>
    </ListView.ItemContainerStyle>
    

    【讨论】:

      猜你喜欢
      • 2016-11-01
      • 1970-01-01
      • 2015-03-16
      • 2010-12-21
      • 2018-05-22
      • 2021-09-03
      • 2018-02-11
      • 2011-09-27
      • 1970-01-01
      相关资源
      最近更新 更多