在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);
       }