Trying to understand INotifyPropertyChanged

后端 未结 4 1993
清歌不尽
清歌不尽 2021-01-25 04:25

Several (newbie) questions:

1) I see a lot of

public Person SelectedPerson { get; set; } 

I am assuming this does NOT fire a property

4条回答
  •  我在风中等你
    2021-01-25 04:32

    Yes, Auto Properties do not fire the PropertyChanged event.

    You can get the CanDeletePerson to re-evaluate by adding OnPropertyChanged("CanDeletePerson") to the SelectedPerson setter.

    I'm not sure if your last bit is a question, but you can subscribe to the PropertyChanged event like any other event. MyClass.PropertyChanged += MyClassPropertyChanged

    Where MyClassPropertyChanged is

    private void MyClassPropertyChanged(object sender, PropertyChangedEventArgs args)
    {
        args.PropertyName .... //<-- Name of property changed.
    }
    

    But you shouldn't need to. WPF does the subscribing to the event that it needs to.

提交回复
热议问题