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
Today's content is about a time when the boss...
Although the iPhone can theoretically use an iPad...
Before the use of physical and chemical methods t...
Let us first think about what resources are avail...
I believe that my colleagues in the Internet indu...
Last week, a good friend complained to me, "...
When developing an e-commerce mini program , more...
I don't know if you have Have you ever cooked...
The factors that affect the quotation of Huizhou ...
Hydrogen fuel cell vehicles use hydrogen as fuel ...
PS channel keying case lesson: no longer afraid o...
We have to admit that we live in an age where adv...
Last week, Apple released the official version of...
The 15th meeting of the Conference of the Parties...
There are two types of Ya'an Flowers WeChat a...