Reuse viewModel with parameter

Jan 6, 2013 at 3:58 PM

I have a View and view model, viewModel has parameters such as datacontext and client, that I register in a modules' Initialize() method. I use the view to add a new client and all is well, unity provides a new datacontext and empty Client object. Now I want to use the same view and view model for viewing an existing Client object. How can I tell unity that the viewModel to use should have my Client parameter passed in?

I have tried the following but when I navigate to the View it always uses the viewmodel with no parameter passed???

        _unityContainer.Resolve<IClientViewViewModel>(new ParameterOverride("client", client));
        _regionManager.RequestNavigate("MainRegion", "ClientView");

Jan 8, 2013 at 4:39 AM
Edited Jan 8, 2013 at 4:40 AM

In terms of Unity, the following is effectively a noop: 

_unityContainer.Resolve<IClientViewViewModel>(new ParameterOverride("client", client));

An IClientViewViewModel instance is retrieved from the container but never assigned to any variable.

It looks like you are using Prism so I would recommend posting to the Prism discussion group.  From the sound of it you want to pass a argument to your view model.  Perhaps this link is useful to that end?

Randy Levy
Enterprise Library support engineer
Support How-to