关闭usercontrol的问题 [英] problem in closing the usercontrol

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

问题描述





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

添加了用户控件作为运行时MainWindow中的子项,现在当我单击usercontrol的登录按钮时,它会登录并加载一个新窗口。但我想关闭登录UserControl而不是父窗口。



i试过这段代码



Window parentWindow = Window.GetWindow(this);

parentWindow.Close();



但它会关闭父窗口而不是用户控件。

请帮助我!!



感谢问候,

Sankar

解决方案

没有关闭控件这样的概念。



不仅不需要它,而且并不意味着什么。那是什么意思?您可以1)隐藏控件的实例; 2)永久地从窗口的逻辑树中删除它。

请参阅:

http://msdn.microsoft.com/en-us/library/system.windows。 uielement.visibility%28v = vs.110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/ms753391%28v=vs.110%29.aspx [ ^ ]。



如需删除,请参阅:

http://msdn.microsoft.com/en-us/library/system.windows.controls.panel。儿童%28V = VS .110%29.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.controls.uielementcollection%28v=vs.110%29 .aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/ms590022(v = vs.110).aspx [ ^ ],

http://msdn.microsoft.com/en-us /库/系统.windows.controls.uielementcollection.removeat(v = vs.110).aspx [ ^ ]。



-SA

hi,

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 login UserControl alone not the parent window.

i have tried this code

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

but it closes the parent window not the user control.
Please help me in this!!

Thanks Regards,
Sankar

解决方案

There is no such concept as "close a control".

Not only it is never needed, but it does not mean anything certain. What is that supposed to mean? You can possibly 1) hide an instance of the control; 2) remove it permanently from the the logical tree of the window.
Please see:
http://msdn.microsoft.com/en-us/library/system.windows.uielement.visibility%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/ms753391%28v=vs.110%29.aspx[^].

For removing, see, for example:
http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.children%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.uielementcollection%28v=vs.110%29.aspx[^],
http://msdn.microsoft.com/en-us/library/ms590022(v=vs.110).aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.controls.uielementcollection.removeat(v=vs.110).aspx[^].

—SA


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

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