Interception with Unity in Prism v2 for WPF

Topics: Prism v2 - WPF 3.5
Mar 26, 2010 at 3:28 PM

I cannot get interception to work with Prism v2 (Oct 2009). I am trying to intercept the Setter for any Public Properties and then fire the PropertyChanged event if the property has changed. I can see that the code gets executed (by stepping through with the debugger or adding a debug point). However, the WPF Window controls that are bound to these properties do not get updated. If I subscribe to these events and print to the console, I can print out the property change notifications.

So, if the View has a textbox, which updates the property on the ViewModel, then the property in the ViewModel gets updated. However, if a button on the view (implemented as a DelegateCommand) causes the property to get updated, then the textbox (TwoWay Binding Mode) that is bound to that Property is not updated even though the event is triggered and the console has printed out the information about which property was updated. Has anyone encountered this issue?

I have a sample app that I can upload somewhere if anyone would care to look at it or has encountered this issue. I could upload it to rapidshare if needed. Thanks in advance.

Mar 27, 2010 at 4:58 AM

Hi

Very strange your problem. It is better if you can provide a little bit code. I never encounterer this problem with textBox.

Please upload some code.

Thanks

Blochaou Francois.

Mar 27, 2010 at 1:33 PM

Here is the sample WPF Application that I have written. Wordpress doesn't allow uploads of zip files, so I renamed it to have a pdf extension (rename the file to have a zip extension). Please let me know what I am doing wrong. Thanks in advance. 

Mar 28, 2010 at 11:34 PM

It seems like the problem exists with the TransparentProxyInterceptor. The program works if I change it from TransparentProxyInterceptor to making those properties virtual and declaring a VirtualMethodInterceptor i.e. from

 

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

to

 

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

I don't know why. Any idea?

 

 

Apr 7, 2010 at 6:03 PM

Hi,

As this question appears to be related to Unity specifically (TransparentProxyInterceptor), you might be interested in asking this question in the Unity forums were you might get a more specific answer.

Please let me know if this helps.

Damian Schenkelman
http://blogs.southworks.net/dschenkelman