I am using Visual Studio 2012 C#. I have created a WPF application project with a main window and added a login window to my project. I want to change the startup window to be my login window but can't seem to do so.
I went to the properties but all I see there is Myproject.app - should it not display the forms of my project?
Anyway I have tried running the window from code as well like so :
Application.Run(new Login());
But that does not seem to work. It gives an error saying :
Error 1 An object reference is required for the non-static field, method, or property 'System.Windows.Application.Run(System.Windows.Window)'
Windows 10 operating systemType and search [Startup Apps] in the Windows search bar①, and then click [Open]②. In Startup Apps, you can sort apps by Name, Status, or Startup impact③. Find the app that you want to change, and select Enable or Disable④, the startup apps will be changed after the computer boots next time.
Go to Settings > Apps > Startup to view a list of all apps that can start up automatically and determine which should be disabled. You can sort the list by name, status, or startup impact. A switch next to each app indicates a status of On or Off to tell you whether or not that app is currently in your startup routine.
To change startup window update App.xaml
by changing Application.StartupUri
:
<Application ... StartupUri="MainWindow.xaml">
To change the startup window programmatically go to App.xaml
remove the line StartupUri="MainWindow.xaml"
(This will remove the default startup window configuration), now add the startup event Startup="Application_Startup"
, in App.xaml.cs
private void Application_Startup(object sender, StartupEventArgs e) { If(somecase) { MainWindow mainWindow = new MainWindow (); mainWindow.Show(); } else { OtherWindow otherWindow= new OtherWindow(); otherWindow.Show(); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With