Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF PRISM/Unity viewModel parameter
    primarykey
    data
    text
    <p>I have a view and corresponding view model for adding or editing a customer. </p> <p>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. </p> <p>I save my customer and now want to view another, existing customer record, from my datagrid. </p> <p>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. </p> <p>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?</p> <p><em>edit</em> I register my views in CustomerModule and add a Customers launch button to navigation region like this:</p> <pre><code>public void Initialize() { _container.RegisterType&lt;ICustomerMainView, CustomerMainView&gt;(); _container.RegisterType&lt;ICustomerMainViewViewModel, CustomerMainViewViewModel&gt;(); _container.RegisterType&lt;ICustomerView, CustomerView&gt;(); _container.RegisterType&lt;ICustomerViewViewModel, CustomerViewViewModel&gt;(); _container.RegisterType&lt;ICustomerNavIconView, CustomerNavIconView&gt;(); _container.RegisterType&lt;ICustomerNavIconViewModel, CustomerNavIconViewModel&gt;(); //var view = _container.Resolve&lt;ICustomerMainView&gt;(); //var view1 = _container.Resolve&lt;ICustomerView&gt;(); _regionManager.RegisterViewWithRegion("NavigationRegion", typeof(Views.CustomerNavIconView)); } </code></pre> <p>To add a new customer I have a command with the following:</p> <pre><code>private void OnAddNewCustomer() { try { _regionManager.RegisterViewWithRegion("MainRegion", typeof(Views.CustomerView)); _regionManager.RequestNavigate("MainRegion", "CustomerView"); } catch (Exception ex) { } } </code></pre> <p>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)????</p> <pre><code>private void OnViewCustomer(Customer customer) { try { _unityContainer.Resolve&lt;ICustomerViewViewModel&gt;(new ParameterOverride("customer", customer)); _regionManager.RequestNavigate("MainRegion", "CustomerView"); } catch (Exception ex) { } } </code></pre> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload