开发者

Link between INotifyPropertyChanged and Databinding

I read this

Simple Binding of Data from code behind to XAML

What's the link between 开发者_如何学CINotifyPropertyChanged and Databinding above not clear from the sample code.


You will want to review Data Binding in the MSDN documentation for a more clear description of how data binding is working in Silverlight and WPF. When you define a data binding declaratively in XAML, an instance of the Binding class is created that connects the properties of binding targets and data sources. It is this Binding class that is performing the monitoring and propagation of changes between the target of the binding and the data source.

While it is technically possible to bind to CLR objects that do not implement the INotifyPropertyChanged interface, it is definitely recommended that "for changes to the source object to propagate to the target, the source must implement the INotifyPropertyChanged interface. INotifyPropertyChanged has the PropertyChanged event, which tells the binding engine that the source has changed so that the binding engine can update the target value." See How Data Binding References are Resolved for further details.


if you have a piece of code that needs to update the UI and the UI is bound to a Poperty like in that example, INotifyPropertyChanged is how we can update the UI without having to do anything extra.


When you bind your property in xaml (XP) to property in code (CP), the binding contains link to object, which contains CP and the name of CP. If the object inherits INotifyPropertyChanged, binding system subscribes on PropertyChanged event and every single time it rises, binding system receives property-name string from propertyChangedEventArgs object and updates bindings for all XPs which are binded to CP with that name.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜