Search code examples
silverlightuser-controlschildwindow

Silverlight closing UserControl Childwindow


On my project I show a Usercontrol childwindow for logging in. Now when I want to submit the login values (username, password) the content of that childwindow has become null... You prob think that I made it a 2nd time but no...

Here is my code for creating the childwindow. And for closing it (that's where it fails)

public void openLoginWindow()
        {            
            if (login == false)
            {
                window.Content = new LoginView();
                window.HasCloseButton = false;

                window.Show();
            }
            else
            {

                window.Close();
            }

        }

Thank's for the help

Evert


Solution

  • what is that LoginView object? Is it a custom usercontrol? I'm not sure how your system is working but what I would do is create a specific childwindow for logging in (in that childwindow you can use your LoginView object if you want). Then in code :

    public void openLoginWindow()
    {
       LoginChildWindow dlg = new LoginChildWindow();
       dlg.HasCloseButton = false;
       dlg.Closed += new EventHandler(dlg_Closed);
    
       dlg.Show();
    }
    
    void dlg_Closed(object sender, EventArgs e)
    {
                LoginChildWindow dlg = ((LoginChildWindow)sender);
                dlg.Closed -= dlg_Closed;
    
                //Retrieve your values here
    }