【问题标题】:Why does Windows.Media.VisualTreeHelper.GetChild(...) exit the sub?为什么 Windows.Media.VisualTreeHelper.GetChild(...) 退出子程序?
【发布时间】:2015-06-11 14:24:03
【问题描述】:

我有一个带有列表视图的 vb 应用程序。 我正在测试并最终为我的拖动事件使用了这个子:

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 断点处停止。

【问题讨论】:

    标签: vb.net winforms


    【解决方案1】:

    New Windows.DependencyObject() 没有子级,因此索引 0 不可用

    查看MSDN的重制

    调用GetChildrenCount方法确定总人数 父视觉对象的子元素。

    参考价值可以 表示一个 Visual 或 Visual3D 对象,这就是为什么常见的 这里使用基类型DependencyObject作为参数类型。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-12
      • 1970-01-01
      • 2018-09-11
      • 2012-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多