简体   繁体   English

在C#中将父项添加到UIElement

[英]Add Parent to UIElement in C#

Is it possible to add a parent to the UIElement in C#? 是否可以在C#中向UIElement添加父项? I know it's possible to do it with children like this: 我知道可以和这样的孩子一起做这件事:

(AssociatedObject as Grid).Children.Add(imageObject);

I can't find any way to set the parent of a UIElement , and can't find very much on Google either. 我找不到任何方法来设置UIElement的父级,也无法在Google上找到。

No, it's not. 不,这不对。 The UIElement class actually doesn't support adding a Parent or Children. UIElement类实际上不支持添加父或子。

Your example uses the Grid class (which does, in fact, allow you to add children). 您的示例使用Grid类(实际上,它允许您添加子类)。 You'd have to add the child element to the parent element using the parent's children collection (assuming the parent is of a type that allows adding children). 您必须使用父级的子集合将子元素添加到父元素(假设父级是允许添加子级的类型)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM