在WPF表单应用程序中关闭WPF用户控件 [英] Close WPF user control inside WPF form application

查看:197
本文介绍了在WPF表单应用程序中关闭WPF用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

wpf用户控件是否包含关闭方法,就像在Windows窗体中关闭一样,谢谢.

Does wpf user control contain a method to close, like close in windows form, thanks.

推荐答案

好吧UserControl和Form是两件不同的事情. UserControls放置在窗口内.您有一个与Window绑定的Close方法.如果要从UserControl内部强制执行Window.Close,则绝对可以使用以下操作.

Well UserControl and Form are two different things. UserControls are placed inside the Window. You have a Close method tied up with Window. If you want to force the Window.Close from inside of UserControl, definitely you can do so using the following.

Window parentwin = Window.GetWindow();
parentwin.Close();



但是,如果您只想关闭UserControl,为什么不处理Visibility.您可以使UserControl.Visibility = Collapsed,也可以使用
从父级删除UserControl. container.Children.Remove(usercontrol);

我不知道您想要什么.



But if you want to close only the UserControl, why dont you deal with Visibility. You can make the UserControl.Visibility = Collapsed, or you can remove the UserControl from the Parent using
container.Children.Remove(usercontrol);

I dont know what you wanted from this.


这是一个疯狂的问题.控件在窗体上时如何关闭"?这是零意义.如果要关闭"控件,则可以对其进行动画处理,或仅将其可见性设置为折叠(或同时显示).控件无法关闭",因为它不是一种形式,在我从未使用过的任何框架中都无法使用.
This is an insane question. How would a control ''close'' when it is on a form ? That makes zero sense. If you want to ''close'' a control, you can animate it, or just set it''s visibility to collapsed ( or both ). A control can''t be ''closed'' because it is not a form, not in any framework I''ve ever used.


Ummm

您可以从父控件中删除该控件.这是我假设父控件是Canvas所做的事情
Ummm

You could just remove the control from the parent Control. This is what I did assuming that the parent control is a Canvas
(this.Parent as Canvas).Children.Remove(this);


这篇关于在WPF表单应用程序中关闭WPF用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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