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
[[129047]] When Cyanogen CEO Kirt McMaster announ...
High-strength aluminum bodies, carbon fiber compo...
Speaking of BMW's iconic design, one is rear-...
Paid bidding promotion has always been an importa...
Code address: https://github.com/apatrascu/huntin...
Samsung Electronics' Galaxy S5 flagship smartp...
1. Avoidance (Basics) 1. To avoid dead links, alw...
Recently, a live broadcaster named Gu Wang died s...
[[262147]] Smartphone users' enthusiasm for n...
In May 2023, my country's Mount Everest exped...
I look for advertising ideas everywhere every day...
We are all familiar with age spots. Many people t...
WeChat Guangdiantong advertising : //www.opp2.com...
Among primary school students everywhere, a more ...
A solar eclipse on Earth is caused by the Earth...