一旦我使用 visualTreeHelper.getchild 查找子对象,我将如何获取该对象的名称,甚至对象的其他属性(如宽度或高度)?
IE
这不起作用:
For i As Integer = 0 To VisualTreeHelper.GetChildrenCount(Can1) - 1
Dim ChildVisual As Visual = CType(VisualTreeHelper.GetChild(Can1, i), Visual)
Dim ChildName As DependencyProperty = childVisual.GetValue(Name)
它说“名称”类型的值不能转换为 system.windows.dependencyProperty
这也不起作用(但至少它可以编译):
For i As Integer = 0 To VisualTreeHelper.GetChildrenCount(Can1) - 1
Dim childVisual As Visual = CType(VisualTreeHelper.GetChild(Can1, i), Visual)
Dim GT1 As GeneralTransform = childVisual.TransformToAncestor(Can1)
Dim currentpoint As Point = GT1.Transform(New Point(0, 0))
x = currentpoint.X
y = currentpoint.Y
如果我将鼠标悬停在 childvisual 上,我可以查看它的属性并看到该名称已设置为我在画布 (Can1) 上拥有的图像的名称。但是,X 和 Y 始终为 0。