I have a view and corresponding view model for adding or editing a customer.
If I click the Add new customer button, unity wires me up a nice shiny new CustomerView and passes in my datacontext and view model, and a customer object that are contructor parameters.
I save my customer and now want to view another, existing customer record, from my datagrid.
I have a command that accepts the selectedItem (Customer) from the datagrid and I now want to pass this in to my CustomerView as a parameter, in my Constructor for the View Model.
How do I tell Unity that I now want to build my Views view model with my Client parameter and then navigate to the view?
edit I register my views in CustomerModule and add a Customers launch button to navigation region like this:
public void Initialize()
{
_container.RegisterType<ICustomerMainView, CustomerMainView>();
_container.RegisterType<ICustomerMainViewViewModel, CustomerMainViewViewModel>();
_container.RegisterType<ICustomerView, CustomerView>();
_container.RegisterType<ICustomerViewViewModel, CustomerViewViewModel>();
_container.RegisterType<ICustomerNavIconView, CustomerNavIconView>();
_container.RegisterType<ICustomerNavIconViewModel, CustomerNavIconViewModel>();
//var view = _container.Resolve<ICustomerMainView>();
//var view1 = _container.Resolve<ICustomerView>();
_regionManager.RegisterViewWithRegion("NavigationRegion", typeof(Views.CustomerNavIconView));
}
To add a new customer I have a command with the following:
private void OnAddNewCustomer()
{
try
{
_regionManager.RegisterViewWithRegion("MainRegion", typeof(Views.CustomerView));
_regionManager.RequestNavigate("MainRegion", "CustomerView");
}
catch (Exception ex)
{
}
}
This is fine and I can add a new customer and save details. Now if I want to view the customer I have saved by double clicking the record in my grid I have a command as follows but don't know how to set the CustomerViewViewModel "customer" parameter to be my selectedItem(Customer)????
private void OnViewCustomer(Customer customer)
{
try
{
_unityContainer.Resolve<ICustomerViewViewModel>(new ParameterOverride("customer", customer));
_regionManager.RequestNavigate("MainRegion", "CustomerView");
}
catch (Exception ex)
{
}
}
Thanks.