Does anyone know of a reliable approach for scrolling a WPF DataGrid (.NET 4) to the last row programmatically?
I'm aware of ScrollIntoView(Items[Items.Count-1])
, but this works only if the items are unique.
For instance, consider the following DataGrid which displays all the installed cultures, followed by all the installed cultures:
var cultures = System.Globalization.CultureInfo.GetCultures (System.Globalization.CultureTypes.AllCultures);
var timesTwo = cultures.Concat (cultures).ToArray();
var grid = new DataGrid { ItemsSource = timesTwo };
How can this grid be programmatically scrolled to the last row?
P.S. Another problem with using ScrollIntoView is that if the grid is itself in a scrollable container (e.g., inside another grid), then ScrollIntoView scrolls not only its own grid, but the outer grid as well such that requested element is visible on the screen. This might be beneficial in some cases, but certainly not in others.
For anyone with this problem, the following seems to do the trick: