WPF Datagrid绑定数据

datagrid绑定属性如下(已实现INotifyPropertyChanged),对List进行赋值,会刷新绑定,但是对T(未实现INotifyPropertyChanged)进行赋值,不会刷新绑定

private List _dataList = new List();
        public List DataList
        {
            get { return _dataList; }
            set { SetProperty(ref _dataList, value); }
        }

要想T发生变更时刷新绑定,需要对T实现INotifyPropertyChanged

public class ResultData : BindableBase
    {
        
        private int _total;
        public int Total
        {
            get { return _total; }
            set { SetProperty(ref _total, value); }
        }
}

要想T中属性A根据T中属性B变化而变化,还要在B赋值时刷新A数据

public class ResultData : BindableBase
    {
        

        private int _total;
        public int Total
        {
            get { return _total; }
            set { SetProperty(ref _total, value); }
        }


        private int _b;
        public int B
        {
            get { return _b; }
            set { SetProperty(ref _b, value); Refresh(); }
        }


        private int _c;
        public int C
        {
            get { return _c; }
            set { SetProperty(ref _c, value); Refresh(); }
        }

        private void Refresh()
        {
            Total = B + C;                 
        }

}

你可能感兴趣的:(WPF,wpf)