Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF. How hide/show main window from another window

Tags:

c#

wpf

show-hide

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?

like image 659
Irakli Lekishvili Avatar asked Jul 25 '11 09:07

Irakli Lekishvili


2 Answers

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();
}
like image 97
SynerCoder Avatar answered Sep 19 '22 00:09

SynerCoder


first answer is good but it'll create a new empty window to avoid this problem ( redirect to a previously created window) just modify constructor like this

 public Login(MainWindow parent):this()
{
    m_parent = parent;
}
like image 23
7zawel Avatar answered Sep 19 '22 00:09

7zawel