从UserControl关闭父窗口 [英] Close Parent window from UserControl

查看:77
本文介绍了从UserControl关闭父窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我在WPF中创建一个应用程序,它包含Window和一个Login UserControl

该用户控件是在运行时作为MainWindow中的子项添加,现在当我单击usercontrol的登录按钮时,它将登录并加载一个新窗口。但我想关闭之前的窗口,即登录窗口。



请帮助我!!





感谢和问候,

Krunal Panchal

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

推荐答案

在用户控制'登录'按钮添加这个:



Window parentWindow = Window.GetWindow(this);

parentWindow.Close();





问候,

Mehwish
In user control 'login' button add this:

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


Regards,
Mehwish


试试这个



Try this

if ((this.Parent as ChildWindow) != null)
{
    (this.Parent as ChildWindow).Close();
}


GIYF :)

ChildWindow.DialogResult Property [ ^ ]
GIYF :)
ChildWindow.DialogResult Property[^]


这篇关于从UserControl关闭父窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆