1

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.

8
  • Why don't you go for Splash Screen ?? Commented May 13, 2014 at 16:19
  • @KrishnrajRana it is not a splash screen. It is a Login Screen. A completely new Window. Commented May 13, 2014 at 16:20
  • What "issues" are you having closing the window? Just a design suggestion. If you have to "initialize" a hidden window in order to gather data, there is likely a problem with your design. Consider doing some research on MVVM and separate your data model from your view logic. Commented May 13, 2014 at 16:24
  • @NathanA How would i go about doing this? Commented May 13, 2014 at 17:41
  • @EliteGamer Describing the concept of MVVM is out of scope here. Just google it as it pertains to WPF and have some fun learning the concept. It can be very rewarding over time. Commented May 13, 2014 at 18:31

2 Answers 2

2

(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(); 
Sign up to request clarification or add additional context in comments.

2 Comments

Could you further explain what you mean? Also, what would i put in the Startup URI? Nothing?
Yes the StartUp URI would be removed. This starts the method instead of starting a window for you. One gotcha is that depending on your implemention you might need to also change the shutdown behavior in the App.xaml and control it yourself.
1

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/

1 Comment

The logic needs to be in the MainWindow. It is the one that processes all the data from our API. I just don't want the user to see a blank for, then all of a sudden data appears in their face.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.