简体   繁体   中英

When to implement iNotifyPropertyChanged interface?

From my understanding, it appears that INotifyPropertyChanged is very useful when working with UI elements that are related to one object source. I'm just curious as to why some classes in the .net framework which may in some way be used with the UI do not implement INotifyPropertyChanged ? For example SerialPort class.

Is there a recommended guideline on the use of INotifyPropertyChanged ? or have I totally misunderstood the concept of the interface?

This question was brought about after trying to link several custom user controls to the SerialPort class.

You understood the interface correctly.

But thinking SerialPort class is somehow related to UI is the bad thing. This class is supposed to allow access to this one resource. Nothing more, nothing less. If you want to somehow display information related to SerialPort , you should create your own business class, that will use SerialPort and expose needed information through properties and INotifyPropertyChanged .

Generally INotifyPropertyChanged is implemented on class having business logic of application developed for WPF or Silverlight.

If SerialPort class is used by other applications like WCF or Winform 2.0, INotifyPropertyChanged will be of little or no use.

Anyway its an interface that is understood by WPF framework engine. And You can create a business class which can implement INotifyPropertyChanged and internally hold SerialPort class.

Hope it makes sense.

INotifyPropertyChanged is to allow objects to communicate to their bindings, so in that sense your understanding is correct.

You can wrap the SerialPort to provide this.

I'm not sure why SerialPort doesn't implement this interface, so in that sense I can't answer that part of the question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM