You
CANNOT change the app.g.cs file - this file is auto generated by Visual Studio - “Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.”!
Hook to the
Application.Startup Event[
^] and do your logic there.
Also check the
Application.ShutdownMode Property[
^].
Sample code used in my WPF project:
private void Application_Startup(object sender, StartupEventArgs e)
{
var dlg = new LoginWindow();
MainWindow = null;
if (dlg.ShowDialog() == true)
{
MainWindow = new MainWindow();
MainWindow.Show();
}
}