问题描述:使用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");
            }
        }

        ......
    }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-20
  • 2021-10-14
  • 2022-12-23
  • 2021-08-22
  • 2021-11-07
猜你喜欢
  • 2022-12-23
  • 2021-06-14
  • 2021-08-13
  • 2021-05-27
  • 2021-08-08
  • 2021-09-27
  • 2022-12-23
相关资源
相似解决方案