Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create Master Detail view with two user controls in MVVM?
    text
    copied!<p>I am little confused about how to create Master Detail view with two different user controls.</p> <p>There are three choices,</p> <p><strong>Choice 1</strong></p> <pre><code>CustomerMasterView + CustomerMasterViewModel CustomerDetailView + CustomerDetailViewModel </code></pre> <p>And keep both View Models in App.Resources</p> <p>But by doing this, binding becomes complex with all static resources source markup code.</p> <p><strong>Choice 2</strong></p> <pre><code>CustomerViewModel CustomerMasterView CustomerDetailView </code></pre> <p>Both views share same ViewModel via App.Resources, well even with the binding code has too many items.</p> <p><strong>Choice 3</strong></p> <pre><code>CustomerMasterView + CustomerMasterViewModel CustomerDetailView + CustomerDetailViewModel </code></pre> <p>Both view's have DataContext set to their corresponding ViewModel. Now here is the little issue, CustomerMasterView has Selector (ListBox or DataGrid or whatever), whose SelectedItem needs to be bound to CustomerDetailViewModel's "Customer" Property as two way binding.</p> <p>Does it look good?</p> <pre><code>&lt;!-- CustomerMasterView --&gt; &lt;ListBox ItemsSource="{Binding CustomerList}" SelectedItem="{Binding DataContext.Customer,ElementName=customerDetailView}" /&gt; &lt;local:CustomerDetailView x:Name="customerDetailView" /&gt; </code></pre> <p>But by doing this, I am defying purpose of ViewModel as it adds more dependency in my UI code.</p> <p>Which one is most preferred way or is there any other way? Should I create nested View Models?</p> <p>I am also trying to learn Prism, and I have little confusion of how to do this right, any help will be appriciated.</p>
 

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