WPF. How hide/show main window from another window

Irakli Lekishvili picture Irakli Lekishvili · Jul 25, 2011 · Viewed 29.5k times · Source

I have Two windows MainWindow and Login. The button which shows login located on mainWindow

this.Hide();
        Login li = new Login();
        li.Show();

on Login Window is button which checks password how i can show MainWindow if password is correct?

Answer

SynerCoder picture SynerCoder · Jul 25, 2011

pass a parameter to the loginwindow of type MainWindow. That allows the Login window to have a reference to the MainWindow:

this.Hide();
Login li = new Login(this);
li.Show();

And the login window:

private MainWindow m_parent;
public Login(MainWindow parent){
    m_parent = parent;
}

//Login Succesfull function

private void Succes(){
    m_parent.Show();
}