问题
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