WPF DataGridTextColumn多行输入

编程入门 行业动态 更新时间:2024-10-23 22:26:24
本文介绍了WPF DataGridTextColumn多行输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在.NET 4中使用具有DataGridTextColumn的WPF DataGrid控件。

I am using the WPF DataGrid control in .NET 4 that have a DataGridTextColumn.

我希望能够输入多行文本。 当我将数据绑定到列时,换行符的格式正确,但是我发现编辑文本时无法创建换行符。

I want to be able to enter multi-line text. The line breaks are formatted correctly when I bind data to the column, but I've found no way of creating the line breaks when editing the text.

<DataGrid ItemsSource="{Binding MyMessages}"> <DataGrid.Columns> <DataGridTextColumn Header="Message" Binding="{Binding Path=Message}" Width="Auto"/> <DataGrid.Columns> </DataGrid>

有什么建议吗?

推荐答案

尝试:

<DataGridTextColumn Header="Message" Binding="{Binding Path=Message}" Width="Auto"> <DataGridTextColumn.ElementStyle> <Style TargetType="TextBlock"> <Setter Property="TextWrapping" Value="Wrap" /> </Style> </DataGridTextColumn.ElementStyle> <DataGridTextColumn.EditingElementStyle> <Style TargetType="TextBox"> <Setter Property="TextWrapping" Value="Wrap" /> <Setter Property="AcceptsReturn" Value="true" /> </Style> </DataGridTextColumn.EditingElementStyle> </DataGridTextColumn>

更多推荐

WPF DataGridTextColumn多行输入

本文发布于:2023-11-03 12:47:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555172.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:WPF   DataGridTextColumn

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!