I'm wrapping my entities with a proxy using Castle DP, my entities implement by themselves INotifyPropertyChanged. and raise the event when set is called.
i wrote some unit test on the wrapping to see that the propertychanged event is fired when i manipulate entities through the proxy and they all passed.
the problem is on a real application with a screen, when i bind the screen to a property that is actually a DP开发者_如何学Go, the screen registering to the propertychanged in a different way and it just doesn't work unless i implement a registration management inside the interceptor code
why this is the behavior, what does wpf do on the property that i don't when registering to property changed ?
In castle AOP there is one important thing to keep in mind - the Equals
method is not working as you would expect.
Look here: RRSL-Lite.EntityAOP. I had the same idea - to have AOP for INPC and created this library. Here is a simple sample of how to use it.
A proxy class generated as an Interface Proxy will have explicit interface implementations of properties and the WPF binding won't work unless it explictely matches.
The two solution are to change your binding paths to explicitely include the interface:
{Binding Path=(local:IEntity.ID)} instead of just {Binding ID}
or to use a virtual method proxy for your view models/entities and make any methods you intercept virtual.
This is probably due to the fact you are wrapping your entities with Castle's CreateInterfaceProxyWithTarget
method or similar. If you are relying on your entities to implement INPC and are relaying your PropertyChanged
event hooks to the underlying proxy target, bear in mind when the PropertyChanged
event is raised the sender
will be your entity not your proxy. If you are trying to bind your proxy in WPF it will expect the sender
to be the proxy. If not, it will ignore the change. The solution is to intercept the events and ensure you set the sender
to be your proxy.
精彩评论