2

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>
1
  • Maybe an alternative method ?
    – odez213
    Jan 11, 2011 at 20:21

1 Answer 1

2

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> 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.