本文介绍了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多行输入
发布评论