【WPF】datagrid内容自动换行

image

<DataGrid ItemsSource="{Binding RowsList}" 
          Style="{StaticResource CustomDataGrid}"
          RowStyle="{StaticResource DataGridRow}"
          CellStyle="{StaticResource DataGridCell}">
    
    <!-- 仅显示需要的列 -->
    <DataGrid.Columns>
        <!-- ID列 -->
        <DataGridTextColumn Header="ID" 
                           Binding="{Binding Id}" 
                           IsReadOnly="True"
                           Width="auto" />
        <!-- 原文列 -->
        <DataGridTemplateColumn Header="Original Text" 
                           IsReadOnly="True"
                           Width="*">
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <TextBlock TextWrapping="Wrap" Text="{Binding Src}" />
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>



        <!-- 翻译列 -->
        <DataGridTextColumn Header="Translation" 
                           Binding="{Binding Trg}" 
                           IsReadOnly="False"
                           Width="*"/>
    </DataGrid.Columns>
</DataGrid>
posted @ 2026-01-30 15:04  苦涩如影相随固  阅读(4)  评论(0)    收藏  举报