Click here to Skip to main content
15,900,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everyone,

I am making an application in WPF, which consists of Window and a Login UserControl
That user control is added as a child in MainWindow at runtime, now when i click login button of usercontrol it gets logged in and loads a new window. But i want to close the previous window that is the login window.

Please help me in this!!


Thanks & Regards,
Krunal Panchal
Posted
Updated 14-Feb-18 19:24pm
Comments
Sergey Alexandrovich Kryukov 15-Mar-12 23:21pm    
What's the problem? Is login window shown as modal or not?
--SA

In user control 'login' button add this:

Window parentWindow = Window.GetWindow(this);
parentWindow.Close();


Regards,
Mehwish
 
Share this answer
 
Try this

C#
if ((this.Parent as ChildWindow) != null)
{
    (this.Parent as ChildWindow).Close();
}
 
Share this answer
 
 
Share this answer
 
"Parent Class"
HTML
<window x:class="X.Parent" xmlns:x="#unknown">
..
>
    <grid>
        <local:childusercontrolc xmlns:local="#unknown"></local:childusercontrolc>
    </grid>
</window>



"Clild Class"
HTML
<usercontrol x:class="X.ChildUserControlC" xmlns:x="#unknown">
...>
    <grid>
         <button content="Cancel" click="cancel">
    </button></grid>
</usercontrol>


private void Cancel(object sender, RoutedEventArgs e)
{
Window parentWindow = Window.GetWindow(this);
parentWindow.Close();
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900