Tag: logical tree

在WPF中断开元素与任何/未指定的父容器的连接

我有一个控件是另一个控件的子控件(因为所有非root控件/元素都在WPF中)。 如果我想将控件移动到另一个容器,我必须先将它与当前容器断开连接(否则抛出exception)。 如果我知道父母是什么,那么我可以将其从子集合,内容或其他任何内容中删除。 但是,如果我不知道父容器的类型是什么 – 如何删除子控件呢? 在下面的代码示例中:如何在不知道父类型(Panel,GroupBox …)的情况下将“sp1”移动到另一个容器? // Add the child object “sp1” to a container (of any type). StackPanel sp1 = new StackPanel(); SomeParentControl.Children.Add(sp1); // Somewhere else in the code. I still have a reference to “sp1” but now I don’t know what container it is in. I just want to move the […]