我正在尝试使用 Castle Windsor Dynamic Proxies 实现 WPF ViewModel。这个想法是我想提供一个接口(下面的 IPerson 应该足以作为示例)、一个具体的支持类和一个拦截器(用于提供 INotifyPropertyChanged 的自动实现)。拦截器实现在这里:http ://www.hightech.ir/SeeSharp/Best-Implementation-Of-INotifyPropertyChange-Ever
我看到的问题是,当我将模型绑定到 WPF 控件时,控件不会将模型视为实现 INotifyPropertyChanged。我相信(但不确定)这是因为 Windsor 正在显式地实现接口,而 WPF 似乎期望它们是隐式的。
有什么办法可以使这项工作,以便模型的更改被拦截器捕获并提升到模型?
所有版本的库都是最新的:Castle.Core 2.5.1.0 和 Windsor 2.5.1.0
代码如下:
// My model's interface
public interface IPerson : INotifyPropertyChanged
{
string First { get; set; }
string LastName { get; set; }
DateTime Birthdate { get; set; }
}
// My concrete class:
[Interceptor(typeof(NotifyPropertyChangedInterceptor))]
class Person : IPerson
{
public event PropertyChangedEventHandler PropertyChanged = (s,e)=> { };
public string First { get; set; }
public string LastName { get; set; }
public DateTime Birthdate { get; set; }
}
// My windsor installer
public class Installer : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
Component.For<NotifyPropertyChangedInterceptor>()
.ImplementedBy<NotifyPropertyChangedInterceptor>()
.LifeStyle.Transient);
container.Register(
Component.For<IPerson, INotifyPropertyChanged>()
.ImplementedBy<Person>().LifeStyle.Transient);
}
}