Solution is ... do everything in the Main
.
For this I have to disable auto-generating Main
(by setting App.xaml
property BuildAction
to Page
, instead of default ApplicationDefinition
) and then I can create own Main
inside Application
class:
public partial class App : Application
{
[STAThread]
public static void Main()
{
}
}
There I have full control over when and how to display windows, do initialization, deinit and such.