The aim is to create an object that contains a number of WPF windows, which would represent a unit that should always be shown together, each Window retaining its own individual responsibilities – say choosing to be laid out on a screen X …
Now because WPF is a single-window architecture, I would like to wrap this list of Windows in a single Window object, so that it could be set as StartupUri, for instance.
- I know I could manually
Show()eachWindowinApplicationstartup, but that is not the point – I need a collection of windows that stick together and which I can easily call upon anywhere in my codebase, knowing I have one class that has taken care of the linkage. - Not interested in Multiple Document Interface MDI here
I do not know how to implement such an adapter, I tried to override BeginInit, but that did not get called at all.
How to stop Window initialization
public class MultiWindow : Window
{
private readonly IList<Window> _windows = new List<Window>();
public void Register(Window window)
{
_windows.Add(window);
}
public override void BeginInit()
{
foreach (var w in _windows)
w.Show();
// base.BeginInit();
}
}
I do not understand Window lifecycle much, is there anyhow I could cancel the initialization and show the list of registered windows instead?
I found a way to do it, which is by making all my windows subclass
BaseWindow, for both normal singleWindowobjects and forWindowobjects actually containing multiple windows..Show()it will either show one window or multiple, depending on what is encapsulated in the subclass.All Window objects should inherit from BaseWindow
Override BaseShow()
Set up MultiWindow in application startup
Use MultiWindow, but call overriden members through BaseWindow
P.S. I wish Microsoft employed interfaces throughout .NET, working with IWindow interface rather than the concrete Window class would provide much more power and in this case, also ease-of-implementation.