How to autoscroll on WPF datagrid

后端 未结 17 977
甜味超标
甜味超标 2020-12-08 09:27

I think I am stupid. I searched now for 15 minutes, and found several different solutions for scrolling on datagrids, but none seems to work for me.

I am using WPF w

17条回答
  •  遥遥无期
    2020-12-08 10:10

    If you used dataview for the datagrid.datacontext, you can use this:

    private void dgvRecords_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
    {
        var dv = dgvRecords.DataContext as DataView;
        if (dv.Count > 0)
        {
            var drv = dv[dv.Count - 1] as DataRowView;
            dgvRecords.ScrollIntoView(drv);
        }
    }
    

提交回复
热议问题