I have a wpf application which uses MVVM. And a view which contains a datagrid in it. This datagrid contains near 30_000 rows. All columns are DataGridTextColumn
and there is a OnSelectionChanged
handler in code behind which just says dataGrid.ScrollIntoView
so when I open this view I see last N rows and the last one is selected at the very bottom of view.
Now I added
<DataGridTextColumn.ElementStyle>
<Style>
<Setter Property="TextBlock.TextWrapping" Value="Wrap" />
</Style>
</DataGridTextColumn.ElementStyle>
to the one of the columns, so height of some rows is changed and when I open the view the last row is placed near the center of view (it is still selected) and the bottom half of the datagrid area is empty.
Then after the first mouse click or scroll over the datagrid is redrawing it and last row takes its place at the very bottom of the view and all look and work fine.
I tried to change selected row in window_loaded
handler but with no lack.
So the question is how to make wpf to evaluate datagrid correctly or just force it redraw datagrid after all evaluations made?