wpfscrollviewerword-wrapdatagridcell

WPF ScrollViewer and TextWrapping inside datagrid cell


I want ScrollViewer and TextWrapping inside datagrid cell. So text inside cell will not crop, and when height of text(block) overflows cell, scrollviewer becomes visible. To sum up I just want to fit all my text into datagrid cell


Solution

  • This should do it for you:

    <DataGrid ItemsSource="{Binding MyData}">
        <DataGrid.Columns>
            <DataGridTemplateColumn>
                <DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock TextWrapping="WrapWithOverflow" Text="{Binding .}"/>
                    </DataTemplate>
                </DataGridTemplateColumn.CellTemplate>
            </DataGridTemplateColumn>
        </DataGrid.Columns>
    </DataGrid>
    

    Could always just change the style instead, but it's just the TextWrapping field that you need.