Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think it is a decent idea.</p> <p>It has the advantage that the ViewModel that wants to show another window doesn't have to use any WPF specific code or even know the view. It only needs to know the ViewModel it wants to show the window for. This is very similar to <a href="http://caliburnmicro.codeplex.com" rel="nofollow">Caliburn.Micros</a> <code>IWindowManager</code>.</p> <p>The thing I don't like about this solution is the static nature of the class. This makes unit testing hard(er). If you are using dependency injection, you could create an interface and an implementation of that interface that is similar to your static class. You could then create an instance of that class in your composition root, bind the ViewModel types to the lambda View factories and register that instance with your DI container. Every ViewModel that wants to show another window now has a dependency on that interface which makes it easily mockable in unit tests.</p> <p>Something like this:</p> <pre><code>interface IWindowManager { void Show(Type type); void Show&lt;T&gt;(); void ShowDialog(Type type); void ShowDialog&lt;T&gt;(); } class WindowManager : IWindowManager { // Implementation of the four methods from the interface plus: private Dictionary&lt;Type, Func&lt;Window&gt;&gt; collection = new Dictionary&lt;Type, Func&lt;Window&gt;&gt;(); public void Bind(Func&lt;Window&gt; ctor, Type type) { ... } } </code></pre> <p>Having the <code>Bind</code> method only on the concrete implementation <code>WindowManager</code> has the benefit that consumers of <code>IWindowManager</code> can't change the registration.</p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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