如何绑定内部运作的?是IObserver比传统INotifyPropertyChanged的更加优化? [英] How Binding internally works? Is IObserver more optimized than traditional INotifyPropertyChanged?

查看:153
本文介绍了如何绑定内部运作的?是IObserver比传统INotifyPropertyChanged的更加优化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 INotifyPropertyChanged的作为第一次在一个简单的WPF应用程序。我想知道究竟如何绑定在内部工作。它是该检查的任何类 INotifyPropertyChanged的的实施和记录需要订户被告知的变化?在CLR

I used INotifyPropertyChanged for the first time in a simple WPF application. I want to know how exactly Binding internally works. Is it the CLR which checks for any class with INotifyPropertyChanged implementation and records the subscribers that need to be informed about the changes?

虽然我想这在.NET 3.5中,我读到的 IObserver 可与.NET 4.0。为 IObserver 超过了传统的 INotifyPropertyChanged的办法优化?

While I tried this on .NET 3.5, I read about IObserver available with .NET 4.0. Is IObserver more optimized than the traditional INotifyPropertyChanged way?

推荐答案

INotifyPropertyChanged的就是这样一个类可以实现一个接口。它是由实现者来决定如何处理的实际变化。

INotifyPropertyChanged is just an interface that a class can implement. It is up to the implementors to determine how to handle the actual changes.

在WPF的情况下,在创建时单向绑定,绑定对象验证如果对象实现INotifyPropertyChanged。如果是这样,它附加一个事件处理程序。这可能是一个弱引用的事件处理程序,因为内存泄漏的担忧,但让我们跳过这个细节现在。当PropertyChanged事件被改变时,绑定对象验证它具有路径是相同的属性名从事件到来。如果是,则结合取的值,并将它转移到在分派的目标。在CLR本身并不关心该事件是什么;订阅通过标准的.NET事件PropertyChanged事件,其只是一个问题。一个重要的一点是,INotifyPropertyChanged的,像顾名思义,是特定事件触发,以指示对象的属性值发生了变化。

In the case of WPF, when a one way Binding is created, the binding object verifies if the object implements INotifyPropertyChanged. If it does, it attaches an event handler. It might be a weak reference event handler, because of memory leak concerns, but let's skip that detail for now. When the PropertyChanged event is changed, the Binding object verifies that the Path it has is the same as the PropertyName coming from the event. If yes, the binding fetches the value and sends it over to the target over the Dispatcher. The CLR itself doesn't care what the event is; its just a matter of subscribing to the PropertyChanged event via standard .Net events. An important point is that the INotifyPropertyChanged, like the name implies, is specific eventing to indicate that an object's property value has changed.

在IObserver接口是为通用通知。这些通知的可以的,我想,是物业通知,但它意味着是一个非常通用的接口。

The IObserver interface is meant for generic notifications. These notifications can, I guess, be property notifications but it is meant to be a very generic interface.

至于优化,这一切都依赖于实现,而不是接口本身。

As to optimizations, it all depends on the implementation, not the interface itself.

这篇关于如何绑定内部运作的?是IObserver比传统INotifyPropertyChanged的更加优化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆