Is it possible to change parent of WPF control

ⅰ亾dé卋堺 提交于 2019-12-12 19:47:04

问题


Is it possible to change the parent of a WPF control? Here is an example:

StackPanel stack1 has Button btn1 in it. There is another empty StackPanel stack2. I want to move the btn1 to stack2 programmatically.

Thanks for the help.


回答1:


You can do this via the StackPanel.Children property:

stack1.Children.Remove(btn1);
stack2.Children.Add(btn1);


来源:https://stackoverflow.com/questions/17222161/is-it-possible-to-change-parent-of-wpf-control

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