Does WPF DataGrid fire an event when a row is added / removed?

前端 未结 7 622
失恋的感觉
失恋的感觉 2021-02-06 05:48

I wish to recalculate things everytime a DataGrid gets more rows or some are removed. I tried to use the Loaded event, but that was fired only once.

I found

7条回答
  •  逝去的感伤
    2021-02-06 06:40

    Have you tried an MVVM approach and binding to an Observable collection?

    public ObservableCollection Items{
    get { return _items; }
    set{ _items = value; RaisePropertyChanged("Items");  // Do additional processing here 
    }
    }
    

    So you can watch the add / remove of items without being tied to the UI?

提交回复
热议问题