views:

37

answers:

1

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?

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.

A: 

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?

Bobby Chopra
I'm not directly familiar with this mechanism, but a proxy will only be aware of actions taken on the proxy. If the SampleViewModel updates one of its own properties internally and doesn't notify the Proxy about it, it has no way of knowing. A VirtualMethodInterceptor is probably creating a descendant class that can actually override the property setters, so now your SampleViewModel code is actually using the overridden implementation.
Dan Bryant