반응형
    public class Model : INotifyPropertyChanged
    {
        private string someText;

        public string SomeText
        {
            get => someText;
            set
            {
                if (someText == value) return;
                someText = value;
                NotifyPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public void NotifyPropertyChanged([CallerMemberName] string name = null)
        {
            if (!String.IsNullOrEmpty(name))
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
            }
        }
    }

 

    public class ViewModelBase : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged = (sender, e) => { };

        public void OnPropertyChanged(string name)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(name));
        }
    }

    public class Model2 : ViewModelBase
    {
        public string SomeText { get; set; }
    }

 

    [AddINotifyPropertyChangedInterface]
    public class Model3
    {
        public string SomeText { get; set; }
    }
반응형

+ Recent posts