问题描述:使用ObservableCollection<OrderItem> source 给Datagrid.ItemsSource赋值,在后台更新source集合后,前台Datagrid对应的单元格数据只有进行编辑模式才会获得更新后的Source数据。

问题解决:如下代码,数据源Model实现INotifyPropertyChanged接口,即可做到实时通知

注:ObservableCollection<OrderItem> source  替换为  List<OrderItem> 也可实现实时通知

 

    public class OrderItem : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string name)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }

        private OpeType state;
        public OpeType State
        {
            get
            {
                return state;
            }
            set
            {
                state = value;
                NotifyPropertyChanged("State");
            }
        }

        ......
    }

 

posted on 2017-01-03 17:07  M小健  阅读(3029)  评论(3编辑  收藏  举报