Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF DataGridTextColumn multi-line input

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?

like image 741
Freddy Avatar asked Jun 15 '11 07:06

Freddy


1 Answers

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>
like image 80
Zahid Sattar Avatar answered Oct 17 '22 06:10

Zahid Sattar