Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Startup Window

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)'

like image 271
Albertus Avatar asked Jun 12 '13 13:06

Albertus


People also ask

How do I change what starts up when I start Windows?

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.

How do I choose which programs open on startup Windows 10?

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.


2 Answers

To change startup window update App.xaml by changing Application.StartupUri:

<Application ... StartupUri="MainWindow.xaml"> 
like image 171
dkozl Avatar answered Sep 23 '22 17:09

dkozl


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();    } } 
like image 35
Vishnu Babu Avatar answered Sep 25 '22 17:09

Vishnu Babu