Question

I have two "MainWIndows". A Login screen and the actual Content Main Window. This is the process in which i want to happen.

  1. User starts application

  2. Clicks Login Button on the Login Window

  3. Initialize the Content Window

  4. Wait until all my lists and Data have been gathered, parse, and added to ListViews

  5. Close the Login Window and show the Main Window. (Make MainWindow the main Window)

I am having issues actually hiding the main window, but i still need to be able to initialize it so i can gather all my data.

I added this to my App.xaml:

<Application.MainWindow>
    <NavigationWindow Source="MainWindow.xaml" Visibility="Hidden"></NavigationWindow>
</Application.MainWindow>

Here is my some of my LoginWindow code:

// Login complete, load the MainWindow Data
MainWindow mainWindow = new MainWindow();
mainWindow.setLoginWindow = this;
mainWindow.InitializeComponent();    //mainWindow.Show();

And the code i am using in the MainWindow:

public partial class MainWindow : MetroWindow {

Window LoginWindow;
public Window setLoginWindow { get { return LoginWindow; } set { LoginWindow = value; } }

public MainWindow()
{
    InitializeComponent();
    // Hide the window to load Data, then on completion, close LoginWindow and show MainWindow:    ::: LoginWindow.Close();
    LoadData();
}

public void LoadData()
{
    // Add player's to list ....

    // Done loading data, show the window
    LoginWindow.Close();
    this.Visibility = Visibility.Visible;
}

}

The Question

How would i do this properly? Also, i want to keep the Focus on the LoginWindow until the MainWIndow has been shown.

Was it helpful?

Solution

(off the top of my head so watch for syntax errors etc...)

Edit the App.xaml and do this:

Startup="StartUp"

Then edit the App.xaml.cs and add a StartUp event like so:

private void StartUp(object sender, StartupEventArgs args)
{
...
}

Then inside you can call your login window and then start your main window after that.

    var login = new LoginWindow();
    if(login.ShowDialog()!=true)
    {
    //login failed go away
return
    }

    var mainWin = new MainWindow();
    mainWin.Show();

OTHER TIPS

I think the problem is that you are putting you logic in the MainWindow. Try putting it in the static Main() method or in the class App: Application class.

Here is a code project where he is doing something similar for a splash screen: http://www.codeproject.com/Articles/38291/Implement-Splash-Screen-with-WPF

Here is a tutorial for working with the App.xaml.cs http://www.wpf-tutorial.com/wpf-application/working-with-app-xaml/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top