我有一个带有listview的vb应用程序。 我正在测试并结束了这个sub为我的dragover事件:
Private Sub ListView1_DragOver(sender As Object, e As DragEventArgs) Handles ListView1.DragOver
XToolStripLabel.Text = "X:" & e.X
YToolStripLabel.Text = "Y:" & e.Y
Dim Insertion As Integer = GetInsertion(MousePosition, ListView1)
SelectionTestTSlabel.Text = "SEL " & Insertion
If CurrentlyDragging Then
Dim gr As Graphics = ListView1.CreateGraphics
Windows.Media.VisualTreeHelper.GetChild(New Windows.DependencyObject(), 0) 'I know this seems like it doesn't do much
MsgBox("") 'I actually added this later because the rest of the code did not run normally.
Dim InsertionY As Integer = 24 + (Insertion * TestItemHeight)
If MyLastInsPoint = Insertion Then
Else
ListView1.Refresh()
gr.DrawLine(New Pen(Color.Gray, 3), New Point(0, InsertionY), New Point(ListView1.Width, InsertionY))
End If
MyLastInsPoint = Insertion
End If
End Sub
我意识到MsgBox(“”)没有弹出消息框,然后我在整个sub上发送了断点。
子运行正常,但在此行之后,
Windows.Media.VisualTreeHelper.GetChild(New Windows.DependencyObject(), 0)
程序返回到表单并且没有执行MsgBox(“”)行。
这条生产线有什么问题?该程序甚至没有停在End Sub断点处。
答案 0 :(得分:0)
新的Windows.DependencyObject()没有子节点,因此索引0不可用
查看MSDN
上的重新制作调用GetChildrenCount方法确定总数 父视觉的子元素。
参考值可以 表示Visual或Visual3D对象,这就是常见的原因 基类型DependencyObject在此用作参数类型。