是否可以更改 WPF 控件的父级 [英] Is it possible to change parent of WPF control

查看:24
本文介绍了是否可以更改 WPF 控件的父级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以更改 WPF 控件的父级?下面是一个例子:

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

StackPanel stack1 中有 Button btn1 在里面.还有另一个空的 StackPanel stack2.我想以编程方式将 btn1 移动到 stack2.

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

感谢您的帮助.

推荐答案

您可以通过 StackPanel.Children 属性:

You can do this via the StackPanel.Children property:

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

这篇关于是否可以更改 WPF 控件的父级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆