WPF Datagrid Binding Doesn't Update Until Clicking Row Header

后端 未结 2 1800
死守一世寂寞
死守一世寂寞 2021-01-08 00:49

I have a datagrid that is bound to a List in the view model. The grid\'s contents don\'t update until I click on the row header. Clicking in various cells doesn\'t affect it

2条回答
  •  清歌不尽
    2021-01-08 00:59

    If you want you grid to update the moment you change the IEnumerable list it is bound to, make it a type of list that implements INotifyCollectionChanged. A built in data type that has this is the ObservableCollection (also here). So if you make your property look like this:

    public ObservableCollection TransactionDetailList
    {
        get { return this._transactionDetailList; }
    
        set
        {
            this._transactionDetailList = value;
            RaisePropertyChanged("TransactionDetailList");                
        }
    }
    

    your grid will automatically pick up any items you add or remove from the list.
    Effectively what you are doing here is notifying when the list has changed (i.e. the list reference), but you are not notifying when the contents of the list have changed.

提交回复
热议问题