In Windows Phone Development 8.1: Data Binding, we learned the basics of data binding. In the next few articles, we will continue to learn more about data binding. Today, we will look at the implementation of the INotifyPropertyChanged interface, which is very important in data binding. Official explanation: The INotifyPropertyChanged interface is used to notify the client (usually the client that performs the binding) that a property value has changed. The official explanation is very vague, and I guess I don’t know when I need to implement the INotifyPropertyChanged interface. Xiao Meng gave a clear conclusion through actual testing: First: OneTime mode: It is meaningless, because its binding is only once at the beginning, and there is no change at all! Naturally, there is no implementation of the INotifyPropertyChanged interface. Then there is the OneWay mode: We know that the meaning of the OneWay mode is that every change in the binding source will notify the binding target, but the change of the binding target will not change the binding source. When the data entity class of the binding source does not implement the INotifyPropertyChanged interface, when we change the data source, we will find that the corresponding data on the UI of the binding target will not change immediately. So at this time we need to implement the INotifyPropertyChanged interface. *** is the TwoWay mode: In the TwoWay mode, when the data entity class of the binding source does not implement the INotifyPropertyChanged interface, we find that the change of the control will cause the data source to change immediately, but the change of the data source will not change the binding target control immediately! So when we need the corresponding UI to change immediately when the data source changes, we need to implement the INotifyPropertyChanged interface. In short: when the data source changes and the UI needs to change immediately, we need to implement the INotifyPropertyChanged interface. We can clearly see this through this example:
Background code
You can clearly experience the role of the INotifyPropertyChanged interface by running this example. The implementation of the INotifyPropertyChanged interface in the above example is the most common and universal one. We can simplify this by using the CallerMemberNameAttribute attribute, which determines which attribute name to pass in based on the caller:
So we can call it like this: NotifyPropertyChange("ID") is changed to:OnPropertyChanged(); The best implementation of the INotifyPropertyChanged interface: This so-called *** implementation method is mentioned in the video of channel 9. The implementation method is as follows:
The corresponding calling method is further simplified:
Link to this article: http://www.cnblogs.com/bcmeng/p/3966931.html |
<<: APICloud, China's first "cloud-in-one" mobile application cloud released
>>: Android interview, how to interact with Service
I have been in the Internet circle for 6 years an...
It seems that overnight, those who used to check ...
Open the APP on your phone, no matter which e-com...
Author: Xiao Lin China Rehabilitation Research Ce...
Many businesses have realized the huge advantages...
How is a complete event planned and implemented? ...
Buy monthly pass at super low price First, let’s ...
The new pay-as-you-go interactive query service c...
After experiencing nine consecutive declines, new...
Social traffic platforms refer to platforms that ...
Since it is an Internet company that wants to make...
The Dragon Boat Festival is coming soon, have you...
The opportunity to write this article is due to a...
No one likes to watch ads, but everyone needs to ...
Produced by: Science Popularization China Author:...