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
For SEO promotion, backlinks are a very important...
The Lunar New Year is coming soon! Have you prepa...
Now is an era where everyone has a public account...
[[132243]] Four years ago, then-Nokia CEO Stephen...
The epidemic in 2020 has prevented many offline c...
Most people don’t know they have wisdom teeth. So...
If the Earth is likened to a huge dynasty, then h...
With the official release of Nokia X2, what change...
Needless to say, everyone knows the benefits of d...
A niche domestic brand, without any Taobao market...
This article is a review of my recent practice. T...
We all have data packages for our mobile phones. ...
China is experiencing widespread rain and snow, a...
What is the generally good keyword density for a ...
In previous cases, we mentioned educational insti...