在UserControl中单击按钮时如何删除此UserControl? [英] When the button is clicked inside a UserControl how to remove this UserControl?

查看:95
本文介绍了在UserControl中单击按钮时如何删除此UserControl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我想在wpf中创建一个用户控件,其中包含一个标签,一个TextBox和一个按钮作为删除UserControl,

现在我想要一个简单的方法删除uc

感谢那些帮助过我的人。

Hi all
I want to create a User Control in wpf that contains a lable,a TextBox and a button as remove UserControl,
now i want a simple way to remove uc
Thanks to those who helped me.

推荐答案





您可以创建指向您放置用户控件的父窗口的委托。当单击按钮时,委托将调用该方法,然后它将从窗口中删除控件。



希望这些信息足以让你的工作完成。



祝你好运
Hi,

You can create delegate that will point to the parent window where you have placed your user control. when button is clicked delegate will call the method and subsequently it will remove control from the window.

hope this information is enough to get your work done.

Best luck


它取决于持有usercontrol的容器。

It depends on what the container holding usercontrol.
private void imgRemove_Click(object sender, RoutedEventArgs e)
       {
           ((WrapPanel)this.Parent).Children.Remove(this);
       }


这篇关于在UserControl中单击按钮时如何删除此UserControl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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