How To Raise Property Changed events on a Dependency Property?

后端 未结 5 1865
长情又很酷
长情又很酷 2020-11-30 20:59

I have a control with two properties. One is a DependencyProperty, the other is an \"alias\" to the first one. How do I raise the PropertyChanged

5条回答
  •  时光取名叫无心
    2020-11-30 21:46

    I question the logic of raising a PropertyChanged event on the second property when it's the first property that's changing. If the second properties value changes then the PropertyChanged event could be raised there.

    At any rate, the answer to your question is you should implement INotifyPropertyChange. This interface contains the PropertyChanged event. Implementing INotifyPropertyChanged lets other code know that the class has the PropertyChanged event, so that code can hook up a handler. After implementing INotifyPropertyChange, the code that goes in the if statement of your OnPropertyChanged is:

    if (PropertyChanged != null)
        PropertyChanged(new PropertyChangedEventArgs("MySecondProperty"));
    

提交回复
热议问题