Reputation: 723
I have WPF datagrid databinded to an object List<>
. The issue is one of the DataGridTextColumn
cells have a long multi-line text and the vertical scroll bar doesn't let me scroll through the content of the specific cell instead I can only scroll to the next cell. Have anyone encountered this issue? The code look something like below:
<DataGridTextColumn Header="Value" Binding="{Binding Value}" Width="*">
<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: 2
Views: 2390
Reputation: 723
I got my workaround which is to use dataTemplate. The dataTemplate then contain the TextBox control with the attribute ScrollViewer.CanContentScroll and ScrollViewer.VerticalScrollBarVisibility set.
<DataGridTemplateColumn Header="Value" Width="*" IsReadOnly="True">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox Text="{Binding Value}" AcceptsReturn="True" TextWrapping="Wrap" Height="150" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True"></TextBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
Upvotes: 2