Causing a UserControl to remove itself (WPF)

风流意气都作罢 提交于 2019-11-30 05:34:04

问题


In winforms I usually do Parent.Controls.Remove(this); to have a UserControl remove itself. This isn't working for wpf. My control has button on it to remove the whole UserControl, any ideas how to accomplish this in wpf? Thanks in advance


回答1:


You will need to know the type of the Parent property to remove yourself from your Parent control.

All Panel type parents (Grid, WrapPanel, StackPanel) have the Children property:

i.e. for Grid:

((Grid)button.Parent).Children.Remove(this);

ContentControls (Button, ContentControl, Border) have Content:

i.e. for Button:

((Button)control.Parent).Content = null;


来源:https://stackoverflow.com/questions/4254213/causing-a-usercontrol-to-remove-itself-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!