I've read a good practice with WPF (and GUI in general) saying to open as few windows as possible. But sometimes, you simply don't have the choice.
So I thought about a fast an elegant solution to open a new window and I thought to this:
public static class WinManager
{
private static Dictionary<Type, Func<Window>> collection
= new Dictionary<Type, Func<Window>>();
/* Bind the type of the ViewModel with a lambda that build an
* instance of a window*/
public static void Bind(Func<Window> ctor, Type type) { ... }
/* Search in the dictionary the specified type and show the window
* returned by the lambda*/
public static void Show(Type type){ ... }
/* Search in the dictionary the specified type and show the dialogue
* returned by the lambda*/
public static void ShowDialog(Type type) { ... }
}
type
is the type of the ViewModel binded to the View (that's the window) and the lambda ctor
is used to return a fresh instance of a window.
Is it a good idea to manage windows like this or am I totally wrong?