2010-03-27 20 views
0

我無法在Prism v2中使用截取(2009年10月)。我試圖攔截Setter的任何公共屬性,然後在屬性發生變化時觸發PropertyChanged事件。我可以看到代碼被執行(通過逐步調試或添加調試點)。但是,綁定到這些屬性的WPF窗口控件不會被更新。如果我訂閱這些事件並打印到控制檯,我可以打印出屬性更改通知。在Prism v2中爲WPF截取Unity(不適用於我)

因此,如果View有一個文本框,它更新ViewModel上的屬性,則ViewModel中的屬性將被更新。但是,如果視圖上的按鈕(實現爲DelegateCommand)導致屬性得到更新,則綁定到該屬性的文本框(雙向綁定模式)不會更新,即使事件被觸發並且控制檯已打印出來關於哪個屬性被更新的信息。有沒有人遇到過這個問題?我寫的sample WPF Application。 Wordpress不允許上傳zip文件,所以我將其重命名爲PDF擴展名(將文件重命名爲zip擴展名)。請讓我知道我做錯了什麼。提前致謝。

回答

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)); 

我不知道爲什麼該項目工程。任何想法?

+0

我並不直接熟悉這種機制,但代理只會意識到在代理上採取的操作。如果SampleViewModel在內部更新其自己的屬性之一併且不通知代理,則無法知道。 VirtualMethodInterceptor可能會創建一個實際上可以覆蓋屬性設置器的後代類,所以現在您的SampleViewModel代碼實際上正在使用重寫的實現。 – 2010-03-28 23:54:41