GraphSharp Vertex双击事件

时间:2013-11-17 15:22:35

标签: vb.net graph-sharp

我在winforms应用程序中使用graphSharp但是我在顶点上添加了Node Double Click事件,但问题是如何获得点击顶点的值。

代码:

    Private Sub VertexControl_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs)
                     ' Dim a As String
        'a = GraphCanvas.GetX(Me).ToString
      Msg(a)
    End Sub

    Public Event VertexSelected As VertexSelectedEventHandler

    Public Overridable Sub OnVertexSelected(ByVal vc As VertexControl)
        RaiseEvent VertexSelected(Me, New VertexSelectedEventArgs(vc))
    End Sub
End Class

Public Class TaggedGraphLayout
    Inherits GraphLayout(Of Object, TaggedEdge(Of Object, Object), IBidirectionalGraph(Of Object, TaggedEdge(Of Object, Object)))
End Class

Public Delegate Sub VertexSelectedEventHandler(ByVal sender As Object, ByVal args As VertexSelectedEventArgs)

Public Class VertexSelectedEventArgs
    Inherits System.EventArgs
    Public Property VertexControl() As VertexControl

    Public Sub New(ByVal vc As VertexControl)
        MyBase.New()
        VertexControl = vc
    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

我这样做了(抱歉C#代码)

在我的XAML中,我在stackpanel上定义了包含所有节点数据的处理程序:

<DataTemplate x:Key="componentTemplate" DataType="{x:Type graph:ComponentVertex}">
  <StackPanel Orientation="Horizontal" Margin="5" MouseDown="UIElement_OnMouseDown">
    <TextBlock x:Name="IdBlock" Text="{Binding Path=ID, Mode=OneWay}" Foreground="White"/>
  </StackPanel>
</DataTemplate>

事件处理程序:

    private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e)
    {
        // Check for double-click only
        if (e.ClickCount >= 2)
        {
            // The DataContext is my custom vertex
            var vm = (ComponentVertex)((StackPanel)sender).DataContext;
            MessageBox.Show(vm.ID);
            e.Handled = true; // Avoid further graph handling
        }
    }