問題描述
是否可以更改 WPF 控件的父級 (Is it possible to change parent of WPF control)
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);
(by Dilshod、Reed Copsey)