views:

573

answers:

0

Hello, I'm trying to scroll to the last line in my DataGrid. This is what I'm using right now:

            var border = VisualTreeHelper.GetChild(mainDataGrid, 0) as Decorator;
            if (border != null)
            {
                var scroll = border.Child as ScrollViewer;
                if (scroll != null) scroll.ScrollToEnd();
            }

I had also tried it via ScrollIntoView, but the problem for both method is following: When the Grid gets loaded with a bunch of lines (so the horizontal scrollbar appears), the auto-scrolling works fine. Now when I reload it with less data/lines, the DataGrid only shows me like the last line (at the top)...even though it could display 20 in the Window. I have to scroll up and then down to make it display it properly.

Any ideas how to solve this? If the explanation is too unclear, I could also provide some screenshots.

Thanks a lot!

Cheers, Joseph

PS: Since I have this problem with ListBoxes, ListViews etc. too, I think it's a problem with ScrollViewer and/or Virtualization