【问题标题】:Add Parent to UIElement in C#在 C# 中将父级添加到 UIElement
【发布时间】:2013-05-06 15:36:24
【问题描述】:

是否可以在 C# 中为 UIElement 添加父级?我知道这样的孩子是可以做到的:

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

我找不到任何方法来设置UIElement 的父级,并且在 Google 上也找不到很多。

【问题讨论】:

  • 这没有多大意义。你真的需要这个做什么?
  • Parent 是只读的,当您添加到 Children 集合时它是隐含的。

标签: c# image silverlight xaml uielement


【解决方案1】:

不,不是。 UIElement 类实际上不支持添加父级或子级。

您的示例使用Grid 类(实际上,它允许您添加子类)。您必须使用父元素的子集合将子元素添加到父元素(假设父元素的类型允许添加子元素)。

【讨论】:

  • 谢谢!很多。帮助我理解
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-10-09
  • 1970-01-01
  • 1970-01-01
  • 2020-03-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多