Forcing CM to update view / view model bindings

Topics: Extensibility
Mar 28, 2012 at 6:29 PM

What is the proper way to unbind a view from a view model, dispose of that view, and re-bind a new view to a new view model? I'm not using conventions in my ViewLocator and instead have a IViewMappings service which is configured at the entry point in the application.  My intention is to allow the application to modify the mappings in the IViewMappings service at any time, and have CM automatically change the bindings for the changed mappings.  I'll be able to come up with a way to automate the process, but I just need to understand how to force CM to properly unbind the old view / bind the new view to the existing view model (without creating a new instance of the view model).

Apr 5, 2012 at 5:41 PM

Anyone? I've walked through CM's code but I don't see any methods for unbinding views from view models.  Is there just something I'm missing, or do I need to implement this myself?

Apr 6, 2012 at 3:19 PM

What happens if view caching is turned off?

Apr 6, 2012 at 3:27 PM

@contract: if the Screen is IViewAware, you can get a reference to the view and manipulate it as you like... note that if the view-model(s) implementa INotifyPropertyChanged, you can always fire a PropertyChanged event with empty PropertyName to request for an update of all bindings bound to the view-model properties.

@dbeattie: that views are not cached, so displaying a second time the same view-model will re-generate a view.

Apr 9, 2012 at 5:05 PM

@BladeWise; I understand the IViewAware interface, however, I don't believe it addresses the issue of unbinding currently bound views from view models, so that the view can be properly disposed.  My intention is to completely change all of the views at runtime, so that the existing view model instances don't change, the existing views are disposed, and new views are bound to the existing view model instances.

I expect to be able to re-bind new views to the view models, but I don't see a way to unbind and dispose of existing views.