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
This article will conduct an in-depth analysis of...
Apple finally released the official version of iO...
May Day is coming, and the short holiday is comin...
In recent years, the concept of "dual carbon...
Expert in this article: Yang Chao, MD, attending ...
Review expert: Li Xianhong, National Level 2 Psyc...
On April 10, 2022, the Central Committee of the Co...
When we hear about or see a very good new product...
Pour a bucket of cold water on technicians who ar...
Expert in this article: Dr. Tian Jing, attending ...
As the saying goes "When you reach middle ag...
Course Contents: 1. Section 1: Course Creation Man...
We explore this in three dimensions: Data-driven ...
In modern society, people's pace of life is g...