Implementing INotifyPropertyChanged - does a better way exist?

前端 未结 30 2619
感情败类
感情败类 2020-11-21 05:23

Microsoft should have implemented something snappy for INotifyPropertyChanged, like in the automatic properties, just specify {get; set; notify;} I

30条回答
  •  离开以前
    2020-11-21 05:29

    I suggest to use ReactiveProperty. This is the shortest method except Fody.

    public class Data : INotifyPropertyChanged
    {
        // boiler-plate
        ...
        // props
        private string name;
        public string Name
        {
            get { return name; }
            set { SetField(ref name, value, "Name"); }
        }
    }
    

    instead

    public class Data
    {
        // Don't need boiler-plate and INotifyPropertyChanged
    
        // props
        public ReactiveProperty Name { get; } = new ReactiveProperty();
    }
    

    (DOCS)

提交回复
热议问题