WPF can't close window and run another?
WPF can't close window and run another?
When it was a windows form app, all worked fine..
WinForm Program Class
CODE
static class Program { // add the user to the system. public static HLPUser HLP_User = new HLPUser("Financial_Promotions"); [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // check if logged in, else make user login if(! HLP_User.Is_Logged) { Application.Run(new Login(HLP_User)); if (HLP_User.Is_Logged) { Application.Run(new Financial_Promotions()); } } else { Application.Run(new Financial_Promotions()); } // logout user HLP_User.LogoutUser(); } }
Now that I have ported it to WPF...
CODE
public partial class App : Application { // add the user to the system. public static HLPUser HLP_User = new HLPUser("Financial_Promotions"); [STAThread] static void Main() { Application app = new App(); // check if logged in, else make user login if (!HLP_User.Is_Logged) { app.Run(new Login(HLP_User)); if (HLP_User.Is_Logged) { app.Run(new Financial_Promotions()); } } else { app.Run(new Financial_Promotions()); } // logout user HLP_User.LogoutUser(); } }
This is being flagged up in the Financial_Promotions Window class contructor at the point of initialisation (highlighted below).Quote:
'System.InvalidOperationException' {"The Application object is being shut down."}
CODE
public Financial_Promotions()
{
InitializeComponent();
}
Thanks
1DMF
"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
RE: WPF can't close window and run another?
"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music
RE: WPF can't close window and run another?
CODE
CODE
The key points I believe are..
1. You cannot run more than one app as part of the master program (like you can with Win Forms)
2. You must ensure the you switch off the app closing when all forms are closed (ShutdownMode)
3. The pre-main application window must be shown as a dialog to pause code execution.
4. Ensure you set the startup to the method handler (Application_Startup)
5. Ensure you set the App.xaml 'Build Action' to 'Page and the App.xaml.cs to 'Compile'
6. Use an empty app.Run() not the form you want to start with
That was a real headache and a lot of wasted time to get to the same point I was prior to going WPF.
Hey ho, I got there in the end!
"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."
"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"
Free Electronic Dance Music