It is unpossible to handle the Window.Loaded event in a "global" manner because it's routing type is "direct". Direct routed events do not follow a route, they are only handled within the same element on which they are raised.
Hovewer you can use the following trick to handle any window creation in your application:
// Main window initialization code
_argsField = typeof(DispatcherOperation).GetField("_args",
BindingFlags.NonPublic | BindingFlags.Instance);
Dispatcher.Hooks.OperationCompleted += Hooks_OperationCompleted;
}
FieldInfo _argsField;
void Hooks_OperationCompleted(object sender, DispatcherHookEventArgs e) {
if(e.Operation.Priority == System.Windows.Threading.DispatcherPriority.Loaded) {
var source = _argsField.GetValue(e.Operation) as System.Windows.Interop.HwndSource;
if(source != null) {
Window w = source.RootVisual as Window;
// ... here you can operate with newly created window
}
}
}