Programmatically scrolling WPF 4 DataGrid to end

后端 未结 1 663
南方客
南方客 2020-12-19 23:03

Does anyone know of a reliable approach for scrolling a WPF DataGrid (.NET 4) to the last row programmatically?

I\'m aware of ScrollIntoView(I

相关标签:
1条回答
  • 2020-12-19 23:59

    For anyone with this problem, the following seems to do the trick:

    var scrollerViewer = GetScrollViewer();
    if (scrollerViewer != null) scrollerViewer.ScrollToEnd();
    
    ...
    
    ScrollViewer GetScrollViewer()
    {
       if (VisualTreeHelper.GetChildrenCount (this) == 0) return null;
       var x = VisualTreeHelper.GetChild (this, 0);
       if (x == null) return null;
       if (VisualTreeHelper.GetChildrenCount (x) == 0) return null;
       return VisualTreeHelper.GetChild (x, 0) as ScrollViewer;
    }
    
    0 讨论(0)
提交回复
热议问题