18

我在让 TextWrapping 在此示例中工作时遇到问题。谁能看到我在这里做错了什么?

    <ListView Name="listViewReportedException" ItemsSource="{Binding ExceptionDetails}">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Time" DisplayMemberBinding="{Binding Thrown}" Width="150" />
                <GridViewColumn Header="Description" DisplayMemberBinding="{Binding Description}" Width="385">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock TextWrapping="Wrap" Text="{Binding}" Width="385"/>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn Header="Recover action" DisplayMemberBinding="{Binding Action}" Width="90"/>
            </GridView>
        </ListView.View>
    </ListView>
4

2 回答 2

36

您同时设置DisplayMemberBindingCellTemplateDisplayMemberBinding使用时删除CellTemplate。也删除Widthfor TextBlock,它会工作

<ListView ...>
    <ListView.View>
        <GridView>
            <!-- ... -->
            <GridViewColumn Header="Description" Width="385">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock TextWrapping="Wrap" Text="{Binding Description}" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <!-- ... -->
        </GridView>
    </ListView.View>
</ListView>
于 2012-06-19T13:05:46.567 回答
0

为 TextBlock 设置样式也对我有用:

<ListView ItemsSource="{Binding xxx}">
  <ListView.Resources>
     <Style TargetType="TextBlock">
        <Setter Property="TextWrapping" Value="Wrap"/>
     </Style>
  </ListView.Resources>
  <ListView.View>
    <GridView.Columns>
      <GridViewColumn Header="Inspection Item" DisplayMemberBinding="{Binding InspectionItem}"/>
  </ListView.View>
<ListView>

在此处输入图像描述

于 2021-11-15T14:36:09.310 回答