Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you got there makes sense and in both cases is a View-first approach to creating a viewmodel. I.e. the view creates the ViewModel. In the original example the viewmodel is created outside of the view (and is sometimes referred to as <a href="http://vincenthomedev.wordpress.com/2009/10/07/view-firstxaml-vs-viewmodel-firstdi-via-constructor/" rel="nofollow noreferrer">marriage pattern</a>), but as far as I am concerned that's the same thing - creation of the view creates the ViewModel.</p> <p>If this suits your needs stick with it. Another approach you might look into is ViewModel first where the viewmodel takes a dependency on the view like so:</p> <pre><code>//In the bare-bones(i.e. no WPF dependencies) common interface assembly interfac IView { void ApplyViewModel(object viewmodel); } interface IMainView : IView { //this interface can actually be empty. //It's only used to map to implementation. } //In the ViewModel assembly class MainViewModel { public MainViewModel(IMainView view) { view.ApplyViewModel(this); } } public partial class MainView : UserControl, IMainView { void ApplyViewModel(object viewmodel){ DataContext = viewmodel; } } </code></pre> <p>Then you can inject this view like so:</p> <pre><code>IRegion region = regionManager.Regions["MainRegion"]; //This might look strange as we are resolving the class to itself, not an interface to the class //This is OK, we want to take advantage of the DI container //to resolve the viewmodel's dependencies for us, //not just to resolve an interface to the class. MainViewModel mainViewModel = container.Resolve&lt;MainViewModel&gt;(); region.Add(mainViewModel.View, "MainView"); region.Activate(ordersView.View); </code></pre>
    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.
    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