2015-06-11 47 views
0

我有一个列表视图的VB应用程序。 我测试并结束了与此子我dragover事件:为什么Windows.Media.VisualTreeHelper.GetChild(...)退出子?

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(“”)不弹出一个消息框,然后我的垃圾邮件对整个子断点。

子跑了作为正常的,但该行后,

Windows.Media.VisualTreeHelper.GetChild(New Windows.DependencyObject(), 0)

程序返回的形式,并没有执行MSGBOX(“”)线路。

这条线有什么问题?该程序甚至没有停在End Sub断点处。

回答

0

新Windows.DependencyObject()没有孩子,所以索引0是不可用

查看MSDN

调用GetChildrenCount方法remaks确定 子元素的总数父母的视觉。

引用的值可以代表一个Visual或Visual3D对象,这就是为什么常见的 基类型DependencyObject在此用作参数类型。