How to autoscroll on WPF datagrid

后端 未结 17 1022
甜味超标
甜味超标 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:15

    Here's another excellent solution.

    public sealed class CustomDataGrid : DataGrid
    {
        protected override void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
        {
            base.OnItemsSourceChanged(oldValue, newValue);
        }
        protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
        {
            base.OnItemsChanged(e);
            if (this.Items.Count > 0) this.ScrollIntoView(this.Items[this.Items.Count - 1]);
        }
    }
    

提交回复
热议问题