用Prive v2 for WPF拦截Unity(不适用于我)

时间:2010-03-27 13:40:44

标签: .net wpf unity-interception

我无法拦截使用Prism v2(2009年10月)。我试图拦截任何公共属性的Setter,然后在属性发生变化时触发PropertyChanged事件。我可以看到代码被执行(通过调试器或添加调试点)。但是,绑定到这些属性的WPF窗口控件不会更新。如果我订阅这些事件并打印到控制台,我可以打印出属性更改通知。

因此,如果View有一个文本框,它会更新ViewModel上的属性,那么ViewModel中的属性会更新。但是,如果视图上的按钮(实现为DelegateCommand)导致属性更新,则绑定到该属性的文本框(TwoWay绑定模式)不会更新,即使事件已触发且控制台已打印出来有关哪个属性已更新的信息。有没有人遇到过这个问题?

这是我写的sample WPF Application。 Wordpress不允许上传zip文件,因此我将其重命名为pdf扩展名(将文件重命名为zip扩展名)。请让我知道我做错了什么。提前致谢。

1 个答案:

答案 0 :(得分:0)

似乎TransparentProxyInterceptor存在问题。如果我将它从TransparentProxyInterceptor更改为将这些属性设置为虚拟并声明VirtualMethodInterceptor,即

,该程序将起作用
        _container.RegisterType<SampleViewModel>()
            .Configure<Interception>()
            .SetDefaultInterceptorFor<SampleViewModel>(new TransparentProxyInterceptor())
            .AddPolicy("NotifyPropertyChanged")
            .AddMatchingRule(new PropertyMatchingRule("*", PropertyMatchingOption.Set))
            .AddCallHandler(typeof(NotifyPropertyChangedCallHandler));

        _container.RegisterType<SampleViewModel>()
            .Configure<Interception>()
            .SetDefaultInterceptorFor<SampleViewModel>(new VirtualMethodInterceptor())
            .AddPolicy("NotifyPropertyChanged")
            .AddMatchingRule(new PropertyMatchingRule("*", PropertyMatchingOption.Set))
            .AddCallHandler(typeof(NotifyPropertyChangedCallHandler));

我不知道为什么。有什么想法吗?