Reputation: 359
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>
Any suggestions?
Upvotes: 20
Views: 20315
Reputation: 11
xmlns:wtk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
<DataTemplate x:Key="dataGridMultiLineTextBoxTemplateColumn" DataType="your data type">
<wtk:MultiLineTextEditor
x:Name="MultiLineTextBox"
Width="300"
Margin="2"
Padding="5,0,0,0"
FontSize="12"
FontWeight="Normal"
Foreground="Black"
IsSpellCheckEnabled="True"
Text="{Binding your binding property, Mode=TwoWay, NotifyOnTargetUpdated=True, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged}"
TextWrapping="Wrap" />
</DataTemplate>
Extended WPF Toolkit MultiLineTextEditor will provide what you need. Extended WPF Toolkit MultiLineTextEditor
Upvotes: 0
Reputation: 1517
Try:
<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>
Upvotes: 38