首页 > 解决方案 > 在ListView中显示内容,文字被截断

问题描述

我在 ListView 中显示内容,文本被截断。即使此文本更长,也无法进一步移动水平滚动条。你知道如何解决这个问题吗?非常感谢你。

   <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid Margin="20">
        <ListView x:Name="ProductDetails"
                 ItemsSource="{Binding ProductDetailsCollection}"
                 HorizontalContentAlignment="Stretch"
                 VerticalAlignment="Stretch"
                  />
    </Grid>

在此处输入图像描述

标签: wpfxaml

解决方案


要解决此问题,您可以Style在窗口中创建一个新的,如下所示:

<Style TargetType="ListViewItem">
     <Setter Property="HorizontalContentAlignment" Value="Stretch" />
     <Setter Property="HorizontalAlignment" Value="Stretch" />
     <Setter Property="Width" Value="Auto" />
</Style>

它应该调整文本并防止被切断。

如果您已经为您ListView或您的ListViewItem支票提供了自定义样式,那么您不会像我发布的那样覆盖属性


推荐阅读